cancel
Showing results for 
Search instead for 
Did you mean: 

Discussions

Mukesh2
Journeyman III

Build tag in azure devops releases

Only start an Azure DevOps release stage if a specific artifact exists In Azure DevOps, I have one build pipeline that runs which could produce 1 or 2 artifacts I want to release. Lets call them Artifact1 and Artifact2.

Is it possible to have one release pipeline with multiple stages that only start if a specific artifact exists? So if Artifact1 was produced, run the Stage Artifact1Stage, but not Artifact2Stage.

I see there are branch filters in DevOps, but that doesn't get me what I want. I want to filter on the artifact produced.

In the Deployment group job (in a stage) there is an Artifact download option which allows me to select the specific artifact I want, but this doesn't prevent the stage from running (and then failing if the specific artifact wasn't produced).

0 Likes
2 Replies
Athonii
Journeyman III

One little known feature of Azure DevOps Pipelines is the ability to tag a pipeline run. By default this is a manual process. Once the build has completed you select Edit Tags and add the values. 

DevOps Projects does all the work for the initial configuration of a DevOps pipeline including everything from setting up the initial Git repository, configuring the CI/CD pipeline, creating an Application Insights resource for monitoring, and providing a single view of the entire solution with the creation of a DevOps Projects dashboard in the Azure portal.

0 Likes
vastitesinc
Journeyman III

Azure DevOps doesn't provide a direct built-in feature to conditionally start a release stage based on the presence of a specific artifact in a release pipeline. However, you can achieve this using a combination of release gates and conditions. Here's how you can approach it:

1. **Release Gates:**
You can use the "Gates" feature in Azure DevOps to introduce conditions before a release stage starts. You would set up a release gate that checks whether the specific artifact exists. If the condition is not met, the gate will block the stage from starting. You can create custom release gates using scripts or use predefined gates like "Artifact download."

2. **Release Stage Conditions:**
While you can't directly conditionally start a stage based on artifact presence, you can control the conditions under which a stage runs. Each release stage can have a "Run on agent" condition that can be customized using pre-defined expressions. You could potentially use variables in these conditions to control the behavior.

Here's a high-level guide on how you might set up this kind of conditional behavior:

1. **Artifact Naming Convention:**
Ensure your build pipeline produces artifacts with clear naming conventions that indicate their purpose (e.g., Artifact1, Artifact2).

2. **Release Gates:**
Set up a release gate (using scripts or predefined gates) that checks for the presence of a specific artifact. If the artifact doesn't exist, the gate would block the stage from starting.

3. **Release Stage Conditions:**
For each release stage, use the "Run on agent" condition to control the stage's behavior. You can use predefined variables like `$(Release.Artifacts.{artifact alias}.SourceVersion)` to check if the artifact exists or has a specific version.

For example, you could set a condition like:
```
and(succeeded(), eq(variables['RELEASE_ARTIFACT1_PRESENT'], 'true'))
```

To set these conditions dynamically, you might need to script the release pipeline YAML or use REST API calls to update the release stages' conditions based on the status of the gates.

0 Likes