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

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

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://learn.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://learn.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

Gitlab: How to run a deploy job on a tagged version / release?

I have created several releases of my backend service in gitlab. Now I want to be able to pick one of them and run the deployment job in my gitlab pipeline on it. SO that the specific version gets deployed. (I'm creating release notes to each release so I can pick which release should now get deployed.)
This is my deployment job in the gitlab-ci.yml:
So far I have used this job like this: When a feature branch was merged into the master and the stand could be deployed and passed all the tests, then the job was triggered manually in the pipeline overview page. Now that I'm using tags to tag each new master version, I want to be able to deploy a version/release from the tags.
Does anyone have an idea how this could work in principle? It would be best if I had a dropdown menu where I can select one of the releases and then trigger the deployment job for it.
The job needs to not get run in the master pipeline, but in the tags pipeline
only:
refs:
- tags
when: manual
This way I can copy the tag of the version that I want to deploy:
and search for it in the pipelines overview page to then trigger the deploy job manually:

How to automatically trigger releases in Azure Devops, from multiple branches, using multiple artifacts

Say you have a build and its corresponding release definition on Azure Devops.
Generally, the way it's used is like:
Repository "A" changes -> Build repo "A" -> Release to a given environment
Within this scenario (using only one build artifact), it's easy to trigger deployments (after successful build) for different branches.
But, say you also have a release definition with multiple build artifacts (from different repos), and you want to, changes coming from branch "dev" you want to deploy to environment "Development", but if changes come from branch "hotfix" you want to deploy to environment "Staging".
Something like this
You can play with branch filters on the specific environment and artifact filters on the artifact triggers.
The above scenario works very well for "dev" changes when you define your build artifacts to use "dev" as default branch.
But if you make changes on Repo A (branch hotfix), but not in Repo B, the build artifacts for that release will come from different branches, hence the "artifacts will not meet requirements", cause all changes must come from hotfix branch in order to trigger the deployment.
In my opinion, the "Default Version" of the Build Artifact itself, makes this confusion for the pipeline.
See this image example
That being said, how can we trigger a deployment into "Staging" environment if only one of the triggered changes come from the branch "hotfix" ?
The way I can see, when that happens, "Staging" environment never "meets the artifacts requirements", cause other artifacts will use version from "dev" as it's the default source branch.
Has anyone worked with a similar scenario ?
Thanks for reading my question.
Update:
According to your scenario, the best solution at present is to create two release pipelines to deploy separately, because Artifact A and Artifact B have no dependencies.
In the Continuous deployment trigger of the build artifact, you can set Build branch filters to include the dev and hotfix branches.
Then enable Artifact filters in the Pre-deployment conditions of the stage to set the build branch artifact conditions that trigger the deployment.
Artifact filters: Select artifact condition(s) to trigger a new deployment. A release will be deployed to this stage only if all artifact conditions match.

Running through the Azure DevOps Fundamentals for beginners course, having trouble with the release pipeline

So I'm currently trying to proceed through the release pipeline portion of an Azure DevOps Fundamentals for beginners course on Udemy, and the goal is to deploy the code for a small webapp game called "Flatris" for the purpose of showing how Azure works.
I've been following along with all the steps as per the course, but when I run the release pipeline build, it consistently fails with the message:
"Error: No package found with specified pattern: D:\a\r1\a***.zipCheck if the package mentioned in the task is published as an artifact in the build or a previous stage and downloaded in the current job."
So far, I've double checked the function of the Web App resource provided through Azure, it's showing traffic when I try and run the pipelines, so it's not the problem(i think), I've double checked the repositories, and they seem to be functioning well(i think), I'm unsure about the artifacts and whether that may be the source of the problem, but theres not enough specificity in the error logs for me to accurately isolate where the problem is.
I don't know if anyone else has managed to get pat this problem, or if it's unique to me with something I'm doing, but any help would be greatly appreciated.
Error: No package found with specified pattern: D:\a\r1\a***.zip
Check if the package mentioned in the task is published as an artifact in the build or a previous stage and downloaded in the current job."
When we use release pipeline for our application, we have to specify the artifacts that make up the application. And the artifact is a deployable component of your application. It is typically produced through a Continuous Integration or a build pipeline. Azure Pipelines releases can deploy artifacts that are produced by a wide range of artifact sources such as Azure Pipelines build, Jenkins, or Team City.
According to the error message, it seems you are using the build pipeline as artifact resource in the release pipeline.
To resolve this issue, we need make sure we have use the Publish build artifacts task to publish the artifacts to the Azure Pipelines in the build pipeline.
Then select the above build pipeline when we select the artifact source type:
In this case, Azure release pipeline will download the artifact automatically when we execute the release pipeline, the artifact will be save in the default folder D:\a\r1\a. That will resolve your issue.

What is the difference between Continuous deployment trigger and Pull request trigger?

Azure DevOps Release pipeline artifact settings has 2 options:
Continuous deployment trigger - Enabling the trigger will create a new release every time a new build is available.
Pull request trigger - Enabling this will create a release every time a selected artifact is available as part of a pull request workflow
I am trying to understand what is the difference between these options with respect to the highlighted parts and whether the build validation policy causes release to trigger with both options, if so then why do we have pull request trigger?
In my opinion, these two triggers have different working scope.
Assuming we set one CI build as release artifact, according to my test:
1.Continuous deployment trigger:
Whenever we have a new version of the Build, it triggers the release. It means that no matter the build pipeline is triggered by manual run, CI trigger or build validation in branch policy, the release is triggered when there's one newer build.
2.Pull request trigger:
It has a smaller scope, it will be trigger by the build pipeline which is trigger by build validation in branch policy.
(Which is triggered by PR, so if we create new PR=>It triggers PR build=>It triggers PR release)
Feel free to correct me if I misunderstand anything.
Update1:
Here's one pic about my two tests:
Release-8 is triggered by my manual running Build pipeline with only CD triggered enabled. And Release-7 is triggered by PR build with only PR triggered enabled. (I only enable the Pull Request for deployment in Stage 1)
Apart from working scope, these two triggers also have a little difference here. The Pull Request Deployment in stage for now is only for PR trigger in Artifact.
This explains that very well (taken from documentation):
Pull requests (PRs) provide an effective way to have code reviewed
before it is merged to the codebase. However, certain issues can be
tricky to find until the code is built and deployed to an environment.
Before the introduction of pull request release triggers, when a PR
was raised, you could trigger a build, but not a deployment. Pull
request triggers enable you to create pull request releases that
deploy your PR code or PR builds to detect deployment issues before
the code changes are merged. You can use pull request triggers with
code hosted on Azure Repos or GitHub.
New build basically means that your pipeline was executed.
Creating pull request trigger you need to define an artifact which will be later deployed. For this kind of trigger Azure Devops runs your pipeline and produce artifact according to your pipeline/build definition and later use this artifact for deployment.
Both trigger are similar, the difference is when your code will be deployed before or after being merged into main branch.
PR trigger is part of CI - applies when your merge your branch to master
CD trigger - applies only to the master branch

For release pipeline (configured for build artifact) to get triggered, the build pipeline must have the "publish artifact" task?

A release can be triggered when the build artifact is available as shown in screenshot below.
So does this necessitate that for the release pipeline (configured for build artifact) to get triggered, the build pipeline must have the "publish artifact" task?
Agree with Shayki Abramczyk, the answer is No. But I think maybe you need more descriptions to help you understand ~
In your situation, you set build pipeline as release pipeline's artifact. If you've checked this document you would find these statements:
1.When authoring a release pipeline, you link the appropriate artifact sources to your release pipeline. For example, you might link an Azure Pipelines build pipeline or a Jenkins project to your release pipeline.
2.Note from here:
You must include a Publish Artifacts task in your build pipeline. For XAML build pipelines, an artifact with the name drop is published implicitly.
3.Auto-trigger releases feature(CD trigger in artifact): New releases can be created automatically when new builds (including XAML builds) are produced. See Continuous Deployment for details. You do not need to configure anything within the build pipeline. See the notes above for differences between version of TFS.
To sum up, the artifact source here represents a build pipeline instead of the outputs of a build pipeline. So when you enabled the CD trigger in artifact(in your situation a build pipeline), the release is triggered whenever a new build finishes. And this behavior won't be affected by whether the build pipeline has Publish Artifact task to publish the outputs from it.
For the 2.Note: It can be considered as we must include a Publish Artifacts task in build pipeline so that the release pipeline can access the outputs of build pipeline. And then we can deploy the outputs(.dll/.exe or what) to target machines/environments. (Actually we think the must in document should be replaced with It's recommended to/should)
Publish Artifacts task make the build+release process meaningful. Cause if our release pipeline can't access outputs of build pipeline, what should we use to deploy? But whether this task exists or not won't actually affect the CD trigger. (Just like the third statement:You do not need to configure anything within the build pipeline)
The answer is No, the release will be triggered when the build finished even he doesn't have Publish Artifacts step.

Resources