VSTS pass parameter in Pipeline between stages - azure-devops

I have two stages in my pipeline. The first one is the trigger for the second one. I want the parameter from first stage be input/accessible in the second stage.
Is this feasible?
EDIT
The case is when the parameter value is set on stage 1 as of result of ARM or script output, then this value is not visible on next stages.
Thanks

It is not possible this way to share variable from stage1 to stage2 in case when you are changing variable value in stage1, to achieve this you need to persist this value in some storage like for eg. keyvault, azure function or vsts api that you will change value for . The stage1 and stage2 can be running on different agent. What can be done is to edit variable value for stage2, in stage1 add task that is persisting this value using (vsts/tfs/azure devops) api and persisting this on release definition. Api for update release definition https://learn.microsoft.com/en-us/rest/api/vsts/release/definitions/update?view=vsts-rest-4.1

Related

How to add different variables to different stages in a deployment pipeline?

I have a traditional CI -> CD pipeline. In my deployment pipeline, I have 2 stages.
I would like to have JSON transform in each of them with different values in the same variables. The deployment pipeline allows me to set variables for the entire pipeline, not for the specific stage.
How can I set different values for variables in different stages?
Set the variable scope as such:

Share variables across build pipelines in Azure devops

I have 2 build pipelines in my azure devops project, one for building source code and the other one is for
making the setup.
I want the build number generated by the first pipeline that compiles code to be passed to the next pipeline which creates the setup file because i want the setup file to take the same version, so I added a variable group with a variable called sharedBuildCounter.
But when I set sharedBuildCounter the build number in the first pipeline using logging command like this(used inside PowerShell task):
Write-Host "##vso[task.setvariable variable=variable_name;]new_value"
The variable indeed takes the new value and I am able to output the new value using another PowerShell task with one line:
Write-Host $(SharedBuildCounter)
And when I run the next pipeline that builds the setup, I find that sharedBuildCounter is being re-set to the default empty value.
Notice: I found threads that suggests using API rest calls to change variable values, but it don't seem to include a specific pipeline name in case of using pipeline variables(not variable groups).
Variable groups will help to share static values across builds and releases pipeline.
What you need is a way to pass variables from one pipeline to another. I'm afraid to say the is no official way to do this.
As a workaround you could update the value of your variables inside your variable group. There are multiple ways to handle this, Rest API, powershell, 3rd-party extension. Detail ways please refer answers in this question: How to Increase/Update Variable Group value using Azure Devops Build Definition?
If you want to get the value of variable in the pipeline. Since you have used logging command to update that variable.
You need to use Rest API to get that particular build log to fetch related info.
You can use Azure Artifacts to pass information between pipelines. In one pipeline, you write the values to a file and publish the file to an artifact. In the other pipeline, you download the artifact and read the file.
There may be other ways to do it. Azure DevOps allows for free and infinite use of Azure Artifacts in this fashion.
See How to get variable values from pipeline resources in azure pipelines.

Pass Azure devops release pipeline(Classic editor) output variable to multiple jobs in same stage or to multiple stages outside

I am using the release pipeline classic editor and have a requirement of passing an output variable generated in a task to multiple jobs in the same stage or to outside stages. Currently, this output variable is available only inside the same job and I have to write the same task in multiple jobs and stages and I feel it is a redundancy. Is there any way to implement it?.
In the Classic editor, I am afraid that output variables in a different job is not feasible. Please refer to this document .
As a workaround , you can use variables across jobs and stages via variable groups.
First define the variable in the variable group, then update the variable group through rest api or azure cli, and replace the defined variable with the value of the variable generated by the task.
PUT https://dev.azure.com/{organization}/{project}/_apis/distributedtask/variablegroups/{groupId}?api-version=5.1-preview.1
Here is a case about update variable group with powershell script.
Another workaround : You can share values across all of the stages by using release pipeline variables. The solution is updating the Release Definition for the Release Pipeline variable in the Stage where the variable is set.
Define a variable in the release definition Variable.
Use REST API Definitions - Update to update the value of the
release definition variable in the agent job.
Use the updated value of the release definition variable in the next
agent job.
The details info about using REST API to update the value of the release definition variable, you can follow this ticket.
For detailed steps and guide, please refer to this blog .

Setting custom variable in Scheduled Release trigger

I am AzureDevOps for creating a new Release from Scheduled trigger from artifact. Same pipeline can create the release manually.
How can i set the value of a Custom Variable for Release that is triggered from Schedule? One of the Task in my pipeline uses that Variable.
If you set two stages separately, one for manual triggering and one for schedule triggering, then you only need to set getting the variable value for the task in the stage triggered by the schedule.
You can customize a variable and set the value for the variable in Release Variables.
If you want to switch the trigger in one stage: manual or schedule, let the task determine whether to get the variable value according to different triggers. Then you can try to write a script in the powershell task to monitor the
pipeline triggers.Get the variable value if the trigger is schedule.

Is there any way to define an environment variable that is accessible across all stages of the IBM Bluemix DevOps Build pipeline

Would anyone know if there is any magic way to define an env variable that could be accessed from all stages of the DevOps build pipeline?
So far, it seems the only thing you can do is to define env variables shared by all jobs inside the same stage.
I understand that each stage run in complete isolation under the cover, but still I was wondering if any trick could be done to define a common env variable for all stages?
Thanks
Environment variables are per stage. There is currently no way to have the same environment variable across that entire pipeline. You would need to set it on each stage individually.
Environment variables are per stage, correct, so if you want one to exist across all stages in a pipeline, you'll need to add it to each stage.
For a list of built-in environment variables and other information, take a look at this documentation page: https://console.ng.bluemix.net/docs/services/DeliveryPipeline/deploy_var.html