Read a user input while queue a VSTS Build - azure-devops

I want to pass few arguments to the VSTS build tasks while queue a build (The same way we do for Jenkins). How can i do that.
I want to read a comma seperated string and want to pass that argument to a Windows Batch Script task in VSTS build job.
I am new to VSTS, someone please help.

Refer to these steps below:
Add a variable in build definition
Check Settable at queue time option
Specify that variable in Batch Script task

On the Variables tab, add a variable and check the "Settable at queue time" box. The variable will then appear in the queue build dialog, and will appear as an environment variable in your script.

Related

How to set Azure DevOps pipeline variable with Powershell

I currently have a variable in my release pipeline and need to set its value through a Powershell script. The purpose is to have its value available to be used for postman collections in next tasks.
I'm trying to do that in this way but not working.
$content = Get-Content -Path .\token.txt
Write-Host "RP token found: $content"
Write-Host "##vso[task.setvariable variable=readingProgressToken;]$content"
Write-Host "Variable value in pipeline: $(readingProgressToken)"
And this is the variable
variable
Using the set variable command will make the variable available for all the task steps that follow. It will not be available within the scope of the same task. If you break your task into two steps, one set then one test display, I'd expect you would see the setting is probably going to be as-expected for your postman step.
From the documentation:
To set a variable from a script, use the task.setvariable logging
command. This doesn't update the environment variables, but it does
make the new variable available to downstream steps within the same
job.
In the script task (PowerShell, Bash, etc..), if you use the logging command SetVariable to create or update a variable with the specified value, this variable with the new value is only available to the subsequent tasks in the same job.
For the script task which runs the SetVariable command, the new value is not available.
So, if you want to print the new value of the variable, you should print it in another task after the script task.

Set Release.ReleaseDescription automatically from the build. (Azure devops Pipeline)

Good afternoon, I need help with this case, I want to generate a release description in my pipeline builds, I tried to set the variable in the build and I used a group variable but I was not successful, the idea is to generate a build that contains a description of what contains and when generating the new release already has the value in the variable Release.ReleaseDescription, I have a slack task that sends approvals, it would be good to have this description so that the people who approve see what it contains. This manual procedure is currently performed when the release is generated and a description is placed.
Variable group can only share variables with static values from build pipeline to release pipeline. However there is an extension task tool Variable Tools for Azure DevOps Services that can accomplish this. You can follow below steps:
1, You need first to search for Variable Tools for Azure DevOps Services and install it to your organization.
This task include two subtasks as the task describles:.
Variable Save Task - During your build you can save the variables to a json file stored with your other build assets
Variable Load Task - During your Release you can load the saved variables and gain access to them.
2, Then you need to define a variable (BuildDescription)in your build pipeline
3, Add a powershell task to assign a value to variable BuildDescription.
4, add Variable Save Task to save variable BuildDescription to a json file and store it to the build artifacts folder which will be published to azure devops server as a part of aritfacts.
5, in the release pipeline, add task Variable Load Task, and then you can use the variable (BuildDescription) in your release pipeline.
Update:
As above tasks cannot be run on linux system. We can write bash scripts to do the variable save task and variable load task.
To save the variable, you only need to replace above variable save task with bash task to run below command.
echo '{"des":"description"}' > variable-meta.json
To load the variable. Add bash task to replace variable load task
val= ($(jq '.description' variable-meta.json))
echo "##vso[task.setvariable variable=BuildDescription]$val"

variable set in Windows Powershell of Jenkins build, not available in other build steps

I have a Jenkins build with one parameter called VERSION.
Based on the length of the variable i am modifying its value in Windows Powershell and then in the next build step, i want to use it.
But the modified value is not being reflected in the next build step execution, it still refer to the intial value entered as a parameter. I tried ENV,script,global none of them seems to work.
Windows powershell build step
input VERSION=1810(via jenkins build)
if ("$ENV:VERSION".length -eq 4)
{
$ENV:VERSION = "$ENV:VERSION",3 -join "" (here it will be 18103)
}
Write-Output "$ENV:VERSION" (18103 here aswell)
later in the Nexus artifact uploader i refer to this variable as ${VERSION} and the above updated value is not being reflected
(here it is 1810 and not 18103)
Please help
This is a general issue with environment variable scope. Every process inherits the environment variables from its parent, but has its own copy, and any modifications you make will only be reflected in the current process and child processes.
I think you will have to find some way to pass the value to a future step that doesn't rely on environment variables.
You can try to use EnvInject Plugin and set additional PROJ_VERSION=$ENV:VERSION variable in your job. In this case it should be working correctly. If it isn't working within Properties Content directly, try to use injection via file as in this example.
I found another option which works in Freestyle project jobs.
the 1st powershell step:
[Environment]::SetEnvironmentVariable('IMAGE_VERSION', $imageVersion, 'Machine')
the 2nd powershell step:
$imageVersion = [Environment]::GetEnvironmentVariable('IMAGE_VERSION', 'Machine')

Can Bamboo variables be overridden by a Script task?

I'm interested in using a script task to override one of these Bamboo plan variables for subsequent tasks but I'm not sure if it's possible or how to go about doing so. It appears that Bamboo allows for various levels of variable overrides for Build Plans all the way down to particular branches however they all seem to require defining the values within the Bamboo UI. The problem with this is that it requires admin privileges to modify these variables whereas some of them need to be modified by developers that do not have this level of access. As a solution I want to be able to specify some variable overrides in files that exist in the source repository itself.
Attempt 1: Overriding environment variables
I've attempted to set the environment variables exposed by Bamboo using a Powershell script and specifying something like $env:bamboo_xyz = 'ABC' but it doesn't seem to have an effect past the task context in which it was specified in. Presumably Bamboo must be re-setting the environment variables individually for each task or executing them within their own contexts but it's not clear to me exactly from the documentation.
UPDATE: It appears from some testing that environment variables set in one Script task are not available in subsequent Script tasks in the same Job. This leaves me with no apparent way to override variables based on anything other than hard coded values in Bamboo.
Attempt 2: Using the Bamboo Inject Variables Plugin task
I've tried using the Bamboo Inject Variables Plugin task to override variables but because what appears to be a required namespace parameter it only seems to be able to define new variables and not override existing ones.
Enviroment variables are only valid in the current session. So if bamboo starts one script ( one powershell session ) completes that and then start a new powershell script ( New Session ) the enviroment variable will not be kept.
So then there are a few options, set the variable in each script.
Or set it using registry at the start of the process. And if ncessary set it back to default value in the last step/script.

VSTS builds - how to define new variable in custom build step and pass to next build steps

We are using VSTS to build our VS solution.
Is there a way to define custom Build Step, for example a PowerShell script, that creates a new variable to be passed to further build steps?
There's nothing about it in MSDN:
https://msdn.microsoft.com/Library/vs/alm/Build/scripts/variables
You can use Task Logging Commands to do this.
To invoke a logging command, simply emit the command via standard
output. For example, from a PowerShell task:
"##vso[task.setvariable variable=testvar;]testvalue"
For Mac, do this :
echo '##vso[task.setvariable variable=variableName;]'$variableValue