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

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"

Related

How to read release pipeline variable and use as environment variable in Azure DevOps in Azure CLI task?

I am using one powershell task and one Azure Cli task in release pipeline of Azure DevOps.
I have some release pipeline's variables. I want to read those variables as they will be required by my script in above two tasks. I used powershell core in Azure cli task
I tried to read them in the inline script directly as $(variableName) or $env:variableName but none of the above worked.
I tried to set read the variable in Environment variables option in the task and then use in the inline scripts using $env:variableName but it also didn't work. On printing the variableName in the script using Write-Host, the value I got is $(valueName) instead of the correct value.
How to read those variables inside these scripts?
The pipeline variables can be reference in the Azure CLI inline script by using the syntax $(variableName). I tested by adding the following in a script
write-host "The variable value: $(variableName)"

Updating environment variable on Azure DevOps

In Azure DevOps pipeline, how to update environment variable in variable group so new value persists, so new value can be used even after build is finished.
For example, I'm trying to save new version number, this does not work:
Write-Host "##vso[task.setvariable variable=currentVersion]$newVersion"
how to update environment variable in variable group so new value persists, so new value can be used even after build is finished.
I am afraid there is no such way to update environment variable in variable group and keep it persists after build is finished.
When you use the Logging Command to set the variable, which is environment variable and can only work in the current environment.
So the new value can not be used after build is finished.
on the other hand, just like Daniel said, if we write any persistent value, then this value will compete/conflict with the value in the variable group. The compiler will not know which value to choose.
So, if you want to write any persistent value, we have to update the value in the variable group manually or use REST API to update it in the variable group.
Check the How to modify Azure DevOps release definition variable from a release task? for some more details.
Hope this helps.
Yes, you can update during build, but the Write-Host only persists in the pipeline currently running. You could use Azure CLI and call something like this:
echo %AZ_LOGIN_PAT%|az devops login
az pipelines variable-group variable update --group-id variable_id --org https://dev.azure.com/your_org --project your_project --name VariableName --value %NewValue%
The PAT might be able to be secured better, but this is how I do it. This is a Windows inline command task.

Read a user input while queue a VSTS Build

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.

How to add secret variable as task environment variable in VSTS

This documentation states that secret variables are
Not decrypted into environment variables. So scripts and programs run by your build steps are not given access by default.
One of my build tasks require that an environment variable be set that is stored in a secret variable. Does this mean it's impossible to do this using secret varaibles in VSTS? If not, how do I do this?
For further background, I'm trying to code sign my electron app using electron-builder. It requires that two environment variables be set: CSC_LINK and CSC_KEY_PASSWORD. One of these is the password to a code signing certificate so needs to be kept secure.
Set Environment Variable
Use a Command Line task, like this:
target_environment_variable now contains the value of secret_variable.
Verify
Add a subsequent Command Line task that writes all environment variables to a disk file, like this: (note: in the Arguments text box, write to a folder that both you and build agent can access):
Queue the build definition, then view the file containing the environment variables:
When using the YAML-syntax this can be achieved too:
steps:
- script: |
echo %MYSECRET%
env:
MySecret: $(Secret_Variable)
You can supply variables to pass to tasks in the Variables page of the build definition:
Then they can be passed in to a task as an input like so:

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