Multiple schedules in Azure Devops Release Pipeline for different branches - azure

I have a Release pipeline with three environments. I have a single build pipeline (_TestCM) that builds different branches (develop, Master, release). All branch builds are CI builds.
I applied an artifact filter to each environment.
I want to deploy
Develop branch --> Environment 1 at 11:30 AM, 3 PM daily
Master branch --> Environment 2 at 5 AM, 7 PM daily
Release branch --> Environment 3 at 6 AM, 2 PM daily.
How can I configure the above scheduling requirement in a single release pipeline? Creating multiple release pipelines with single environment in each pipeline is not an option as we have hundreds of release pipelines. Release pipeline need to trigger at the scheduled time only if there are any changes from that branch.
If it is not possible in a single Release pipeline, what are the options we have for accomplishing this task considering the hundreds of Release pipelines?

Based on your requirement, I am afraid that it is not possible in a single release pipeline.
Release pipeline need to trigger at scheduled time only if there any changes from that branch.
For this requirement, there is an Option in Release Pipeline(
Only schedule releases if the source or pipeline has changed).
According to your deploy process, you need to determine the environment via the branches. So you need to add multiple artifacts for multiple branches.
In this case, this option will not meet your needs. It treats all atifacts as a whole. When one of the branches changes, the release will be triggered by the schedule and all artifacts of different branches will be deployed at the same time.
You can achieve your needs by creating multiple pipelines.
The following are the settings you can refer to:
When you add artifacts, you can select the branch and enable the option:Only schedule releases if the source or pipeline has changed.
For example:
In environemnt, you can directly set schedule trigger without other settings.
You need to create the corresponding number of release pipelines according to your branches.

Related

Azure DevOps pipelines - Build triggered multiple times

I am using different YAML files (with different tasks) in different branches.
While triggering it executes multiple times. I don't know what is the reason.
I am using different triggers for different pipelines. eg:
In branch SFCC:
trigger:
- SFCC
In branch SFCC-QA:
trigger:
- SFCC-QA
In branch SFCC-DEV:
trigger:
- SFCC-DEV
When I run the pipeline for SFCC triggered, the same pipeline would start running in another pipeline also with same trigger, because of that app is deploying 2-3 times instead of single time.
Could you please help me with this.
SFCC-QA pipeline:
SFCC pipeline:
You can see in first screenshot(for the date 9th sep and 14th sep), the pipeline is for QA and here pipeline is executing for other branch, which is not mentioned in this particular pipeline. While in the second screenshot pipeline is executing fine for the same date. So you can see 2 times same pipeline is execting on 9th and 14th sep.
Azure build pipeline definition is associated with a repo and YAML file in that repo. The branch is associated at the time only when the pipeline is run. So, it is not something you associate at the time of pipeline definition.
I think in all 3 of your pipelines, the YAML file path is same. You have different trigger (and different other content) in the YAML file in different branches, but your file name/path is same. Hence the same file will trigger the build for each branch where relevant within pipeline.
To get desired results you can use different file name for your YAML file for each pipeline definition. So in SFCC branch have SFCC.yaml and in SFCC-QA branch, have SFCC-QA.yaml.

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

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.

Azure Devops exclude job if branch tag is present

My Azure DevOps pipeline has 3 jobs. One builds the project for production and the other builds it for testing and the last publish artifacts. When I push to release branch, it triggers all of 3 jobs, but they can take 10-15 minutes to finish. What I'm trying to achieve is exclude testing job if a tag is present on the commit or something like that.
Ex. Don't trigger test job if branch tag has "hotfix". Tryed "Run this job with conditions" in job's settings with this value "not(startsWith(variables['Build.SourceBranch'], 'refs/tags/hotfix'))" but if I push something to release with hotfix tag it still runs.
Thanks
We recommend you can use the conditions:
condition: eq(variables['Build.SourceBranch'], 'refs/tags/test')
And this means if you want the test job to run, then you need to push something to release with test tag. We cannot use the value "not(startsWith(variables['Build.SourceBranch'], 'refs/tags/hotfix'))"
On my test, if I push the commit release with hotfix tag, then the test job will be skipped.
Update:
We can use the Custom conditions in Additional options, and set it as :
eq(variables['Build.SourceBranch'], 'refs/tags/test')
More details, you can refer this doc: Expressions

How to setup generic stage pipeline for all environments?

I have multiple artifacts for each branch. Continuous deployment trigger is enabled For Dev: _CI_Dev For QA: _CI_QA For Staging: _CI_RC
I want to setup a common stage (since the tasks are same across environments) which should identify the source branch and use corresponding artifacts.
How to add approval and gates only for QA and staging?
How do I identify the source branch which triggered the tasks (for a job)? Should I run a powershell script to setup source branch value in variable to be used in tasks?
How to add approval and gates only for QA and staging? How do I identify the source branch which triggered the tasks (for a job)? Should I run a powershell script to setup source branch value in variable to be used in tasks?
I am afraid we could not add approval and gates only for QA and staging, if we want enable Continuous deployment trigger for all artifact sources.
That because approval and gates currently do not have separate filters, they rely on the option Artifact filters:
However, if we set the Artifact filters for QA and staging, it will filter out builds from Dev: _CI_Dev. Obviously this is not in line with our expectations.
To resolve this issue, the easiest way is to clone the current stage (Although it can't exactly what you originally expected to use one stage, this is currently the best solution.), it will also clone all tasks in that stage. changing Select trigger from stage to release and set the Artifact filters for QA and staging:
Note: Do not forget to add Artifact filters for Dev: _CI_Dev to the previous stage.

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.

Resources