How to make azure devops release pipeline deploy into a stage only if new version of the artifact comes?

Viewed 517

I have a release pipeline that deploys multiple components using multiple stages. With the current setup i have if a release pipeline triggers then deployment happens in all stages even if new version of artifact is not generated. My requirement is, deployment into stage should happen only if new version of artifact is generated i.e., out of 10 components if only one component got new version of artifact then the stage respective to that should only triggered and other components should be skipped.

FYI: i don't want to create separate release pipelines for the components

2 Answers

I think the condition of the tasks should be able to achieve your requirements.

Just give an idea, for example, if you publish new artifact to DevOps feed, you can use this REST API to get the packages versions:

https://docs.microsoft.com/en-us/rest/api/azure/devops/artifacts/artifact-details/get-package-versions?view=azure-devops-rest-6.0

Then, you can compare the latest version that the REST API returned with the artifact version in your release pipeline.

condition: and(succeeded(), eq(<version in pipeline>, <latest version in feed>))

You can refer to this official document:

https://docs.microsoft.com/en-us/azure/devops/pipelines/process/conditions?view=azure-devops&tabs=yaml

If you have continuous deployment triggers enabled for an artifact, the pipeline creates a new release (with all stages) every time. Since the build artifact trigger is abstracted away from the stages, you can't select a stage per artifact.

You said you didn't want to create a separate pipeline per artifact but that really sounds like the correct design. That way only the associated stage(s) will be deployed when the artifact is updated.

Related