How to pass Variable value between two yaml pipeline in azure - azure-devops

I have two pipelines one is primary which triggers the other. How to pass a variable set on the first pipeline to second triggered one.
Example:
Variable-Name: Validate = True
I want to pass the validate variable to secondary triggered pipeline . I could not find any documentation that would help.

You could store the necessary value to a file, then include this file in current build's artifact (Publish pipeline artifact task).
Then in secondly pipeline, you could add Download Pipeline Artifacts task to download latest artifact of first build and read the content of necessary file.
If you are using pipeline resource (could enable trigger), please add Download task to download artifact of that pipeline resource.
Resources: pipelines

Related

How to select Solution file of a particular project to build in YAML pipeline?

I have two projects lets say A and B under one repository in azure Dev-ops. Each project has its own solution file.
The pipeline have tasks to build the solution and then upload the packages to the feed.
I want to select the solution file for project A if changes in pull requests are targeted for project A.
As of now i have created in a variable with default value and allowing user to override the variable name while triggering pipeline manually. PFB
But how to achieve same behavior to auto trigger the pipelines from
Pull Request. Is there any way to supply solution(.sln) name to
pipeline from pull request?
There is no way to implement that scenario within a single pipeline. Use two pipelines. Use different path filters to ensure the pipeline only triggers when appropriate paths change.

Azure DevOps Build Pipeline Code Version/Merged Changesets

I have scheduled build pipeline thats autmatically triggered by changes in source code. Basically I want to know which changesets got into build before pipeline started to execute.
You can use the predefined variable $(Build.SourceVersion) to get the changeset that triggering your pipeline. For detailed information, please refer to this document.
You can use this variable as part of the pipeline definition or value in the script that you want to run in pipeline. When the pipeline is triggered, this variable will be assigned by the system automatically.

How to specify build variables from a particular artifact?

I am trying to use Predefined Build Variables in my Release Pipeline with CI Trigger enabled. My release pipeline has multiple Artifacts coming in from Multiple separate Build Pipelines.
When I use the variable $(Build.BuildNumber), it targets the variable to a specific artifact all the time. I would really like it to use the one from the Build Pipeline that is triggering the deployment. But if that is not possible, can I at least specify which Artifact-set it should use the Build variables from?
You would probably do this with a combination of information. You would first need to get the trigger artifact alias using a pre-defined release variable: Release.TriggeringArtifact.Alias
Then you want to pull details about a specific artifacts build number, you can reference it using a pre-defined release variable (replacing with the alias from the first variable): Release.Artifacts.{alias}.BuildNumber
The build number or the commit identifier.
Azure Pipelines example: 20170112.1
Jenkins/TeamCity example: 20170112.1
TFVC example: Changeset 3 Git example: 38629c964
GitHub example: 38629c964

The $(Build.ArtifactStagingDirectory) variable's value changes when deploying a build in Azure DevOps Pipelines

I have a DACPAC deployment task which is failing, because for some reason the value of the $(Build.ArtifactStagingDirectory) pipeline variable is changing between the build pipeline and the release pipeline. In the build pipeline, the variable is set to C:\agent\_work\2\a, but in the release pipeline it's C:\agent\_work\r2\a. This is causing the release pipeline to fail when it tries to deploy the DACPAC artifact, because the folder it's looking in is empty; the folder where the artifact actually is is ignored. How do I make these variables consistent between the build and release pipelines so that the artifact is retrieved from the same folder it's generated in? These variables appear to be built in, so I don't see any way to change them. I could always hardcode a path, but that seems a bit kludgy...
In releases you have System.ArtifactsDirectory which is
The directory to which artifacts are downloaded during deployment of a release. The directory is cleared before every deployment if it requires artifacts to be downloaded to the agent. Same as Agent.ReleaseDirectory and System.DefaultWorkingDirectory.
Example: C:\agent_work\r1\a
and in pipelines/builds Build.ArtifactStagingDirectory
The local path on the agent where any artifacts are copied to before being pushed to their destination. For example: c:\agent_work\1\a
A typical way to use this folder is to publish your build artifacts with the Copy files and Publish build artifacts tasks.
Note: Build.ArtifactStagingDirectory and Build.StagingDirectory are interchangeable. This directory is purged before each new build, so you don't have to clean it up yourself.
See Artifacts in Azure Pipelines.
This variable is agent-scoped, and can be used as an environment variable in a script and as a parameter in a build task, but not as part of the build number or as a version control tag.
This is in line with your experience. And you cannot change it, as they are predefined. But can you clarify why this is a problem for you?
In the release pipeline, you can't directly access the files in the build pipeline, not only because the working directory is different, but also because they do not use the same agent. You need to download the artifacts first, and then use them in the release pipeline.
You can use the following ways to download artifacts:
Use the Download Build Artifacts task.
Go to the edit release pipeline page -> Select Add artifact -> Select Build -> Fill in the information related to the build pipeline (Notice the value of Source alias)-> Add it. You will find your artifacts are downloaded in $(System.ArtifactsDirectory)/${Source alias}
For more information about consuming artifacts in release pipelines, you can click this document.
Oh, I think I figured it out. Each release pipeline stage has an option called "Artifact download" which lets you specify which artifacts out of all those linked in the pipeline are actually used by that stage. I needed to check the appropriate checkboxes there in order to use the artifacts in the stage's tasks.

How to pass "settable at queue time" variable value from build pipeline to release pipeline

I have two pipelines on azure devops that do the following:
BUILD PIPELINE
Asks the user for the desire branch name and ticket id (from our ticketing system). Using two "settable at queue time" variables.
Gets the files from the specified branch name, builds the project and generate the artifacts that are later use by the RELEASE pipeline
RELEASE PIPELINE
This release pipeline is being triggered by the completion of the BUILD pipeline specified before. This pipeline completes the following tasks:
Creates new app service slot using an Azure CLI command task. In this task I need the ticket id, in order to create the slot with the corresponding ticket id as its name
Deploy the application to the created app service slot
I haven't found a way to pass to the RELEASE pipeline the ticket id the user entered when running the BUILD pipeline that triggered this RELEASE.
Unfortunately, there's no such a build-in function in Azure DevOps. While thanks to Martin Hinshelwood, we had an extension- Variable Tools for Azure DevOps Services to achieve the goal.
As you can see in the extension's doc, add a Variable Save Task in your build pipeline and a Variable Load Task in your release pipeline. After these two tasks, the variables are fully passed to your release.
Check below as reference: