Only start an Azure DevOps release stage if a specific artifact exists

Viewed 439

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).

EDIT: If it matters, I am not using yaml syntax for the release pipeline.

1 Answers

I would do something like the following (assuming this is classic pipeline as you suggested):

  1. Add a Powershell task whose script inspects the contents of $(System.DefaultWorkingDirectory) (including whatever subfolder contains your artifact) and then uses Write-Host "##vso[task.setvariable variable=whichArtifact;isoutput=true]some value that tells you if it's artifact 1 or 2 that's present"
  2. Create 2 jobs in a single stage, one for each artifact (or two stages with one job each, your call). For the Run on agent job additional option Run this Job, choose Custom condition using variable expressions, and the value would be something like eq(variables['whichArtifact'], 'value that tells you which artifact this is')

The variable value you set and condition you choose should be mutually exclusive so that you can clearly select the stage/job you wish to run.

Related