How to trigger Azure Pipeline on every new push on any branch? - azure

My current implementation of Azure pipelines is to trigger only when a pull request is made to Develop branch. But, I want to run the pipeline on every new push on any branch. How to trigger that?
My current implementation of the Azure YAML file
trigger:
- none
pr:
- branches:
include:
- dev
and below that steps are configured.

You need to specify the trigger something like this. So for example, if there is anything pushed in dev branch a build will get triggered. Ref
trigger:
- dev
or to be more explicit:
trigger:
branches:
include:
- dev
- another-branch
If no triggers are specified it will by default run for all branches. It can be explicitly defined as:
trigger:
branches:
include:
- '*'

In my case, using Azure DevOps, I have this on my .yaml file:
trigger:
- '*'
pool:
vmImage: 'windows-latest'
So, it gets triggered no matter to which branch I'm pushing to.
I hope it might help.
Note: the pool part is not relevant; I just added to give more context.

If you have git and a repo created in your project, you can easily connect git to azure dev ops. So let's say you want to deploy every push you give to the master branch of your repo. You can connect your master branch to the azure DevOps so it deploys it automatically.
This link will provide additional information

Related

Azure Devops pipelines to trigger on PR complete

What I have to do is, I have 1 branch as below in the azure DevOps respository
dev
Then I create a new branch as dev-C123456, so now I have two branches (dev and dev-C123456)
Then I do some changes to dev-C123456 and I create a Pull Request from dev-C123456 to dev. So once the changes are reviewed, the approver will Approve and Complete the pull request.
Right after he clicks Completes, I want a pipeline to run.
Here's my
And I have a auzre-piplines-on-pr.yml which will trigger the pipeline. For example, in dev branch, I have like this;
pr:
branches:
include:
- dev
...
But it never triggers a pipeline, what should I do?
Right after he clicks Completes, I want a pipeline to run.
So put a trigger for the target branch.
trigger:
branches:
include:
- dev
That will run whenever a commit is made to dev, including when the commit is a PR merge commit.

Azure DevOps: Pipeline for all branches but master

I have a website project with two pipelines
1.- PROD pipeline, which is triggered on every master branch push. This builds the site, deploys it and sends an email to the whole company informing about the new version. This works perfectly so far ✅
2.- DEV pipeline: should be triggered on a push to ANY branch that is not master. Builds the site, deploys the site to a DEV stage and sends an email to the author of the commit.
Following the docs, this trigger configuration should trigger the DEV pipeline on all branches but master.
trigger:
branches:
exclude:
- master
include:
- '*'
However, if I then try run the pipeline in any branch that is not master, I get the following error: Encountered error(s): Could not find valid pipeline YAML file for this branch/tag
How can I setup the pipeline, so that it gets triggered by all branches but the master branch?
Thanks in advance for your help!
D
You have to have the YAML file in every branch you want it to trigger for, you cannot just have it in the master branch and expect it to trigger on another branch.

Azure devops service connection and central pipeline

I have a requirement of giving multiple teams access to a shared resource in azure. I therefore want to limit how people can publish changes to the shared resource.
The idea is to limit the use of a service connection to a specific pipeline, as per this documentation. However if the pipeline is stored in their own repo the developer could change it. This would not give me enough control. I therefore found that it was possible using a template from a central repo. Using a shared repo, would then allow me to have a service connection solely for the template?
So how I imagine doing the above is I need to grant project X a service connection for my BuildTemplates Repo. But this is basically just access to the repo and to be able to use the shared templates. Then in BuildTemplates repo I can have a service connection for my template A.
Now the developer in project X - creates her deployments and configurations for her pipeline with her own service connection scoped for her resources. Then she inherits a template from BuildTemplates Repo and passes relevant parameters for the template A.
She cannot alter the template pipeline A and only the template pipeline A can publish to the shared resource, because of the scoped service connection. I can therefore create relevant guards for the shared azure resource in the template pipeline A - so I restrict how developer X can publish to my shared azure resource.
does this make sense and is it viable?
The pipeline part in A cannot be edited by developer in X ?
The service connection in A will not propagate out so developer in X can use it in an inappropriate way?
Update
The above solution does not seem to be viable since the pipeline template is executed in the source branch scope.
Proposed Solution
The benefits I see with the above suggestion doe not seem possible, because of the issues. However one can utilise pipeline triggers, as a viable solution. This however results in a new issue. When a pipeline is triggered by Developer Y in Y's repository and it succeeds. Then a trigger is made in MAIN repository and the pipeline in MAIN fails e.g., because the artifacts from Y introduced an Issue. How does developer Y get notified about the issues in MAIN pipeline?
Here is my solution, in same Azure organization, we can create a Azure Project, then create a repo to save common pipeline template.
All the repos in other Azure project can access this pipeline template.
UserProject/UserRepo/azure-pipelines.yml
trigger:
branches:
include:
- master
paths:
exclude:
- nuget.config
- README.md
- azure-pipelines.yml
- .gitignore
resources:
repositories:
- repository: devops-tools
type: git
name: PipelineTemplateProject/CommonPipeline
ref: 'refs/heads/master'
jobs:
- template: template-pipeline.yml#devops-tools
PipelineTemplateProject/CommonPipeline/template-pipeline.yml
Since the inline script of pipeline has 5000 characters limitation,
you can put your script(not only powershell, but also other languages) in PipelineTemplateProject/CommonPipeline/scripts/test.ps1
# Common Pipeline Template
jobs:
- job: Test_Job
pool:
name: AgentPoolName
steps:
- script: |
echo "$(Build.RequestedForEmail)"
echo "$(Build.RequestedFor)"
git config user.email "$(Build.RequestedForEmail)"
git config user.name "$(Build.RequestedFor)"
git config --global http.sslbackend schannel
echo '------------------------------------'
git clone -c http.extraheader="AUTHORIZATION: bearer $(System.AccessToken)" -b $(ToolsRepoBranch) --single-branch --depth=1 "https://PipelineTemplateProject/_git/CommonPipeline" DevOps_Tools
echo '------------------------------------'
displayName: 'Clone DevOps_Tools'
- task: PowerShell#2
displayName: 'Pipeline Debug'
inputs:
targetType: 'inline'
script: 'Get-ChildItem -Path Env:\ | Format-List'
condition: always()
- task: PowerShell#2
displayName: 'Run Powershell Scripts'
inputs:
targetType: filePath
filePath: 'DevOps_Tools/scripts/test.ps1'
arguments: "$(System.AccessToken)"
Notes:
Organization Setting - Settings - Disable Limit job authorization scope to current project for release pipelines
Organization Setting - Settings - Limit job authorization scope to current project for non-release pipelines
Check some option in project setting as well.
So the normal user only access their own repo, cannot access DevOps project, and DevOps owner can edit template pipeline only.
For the notification issue, I use an Email extention "rvo.SendEmailTask.send-email-build-task.SendEmail#1"

How to trigger azure yml pipeline on tagging master branch only

Regarding azure yml pipeline trigger
How to achieve below requirements
I want to trigger my azure yml pipeline
Should trigger pipeline on master branch if PR is merged to master branch
Should trigger pipeline on master branch if git tag is added on master branch.
Should not trigger pipeline if git tag is added on non-master branches (like develop, features branches)
Should trigger pipeline on non-master branches if PR is merged or commit happens on these branches
How to handle this any idea, I have below trigger set as of now?
trigger:
branches:
include:
- develop
- master
- features/*
paths:
exclude:
- README.md
- azure-pipelines.yml
tags:
include:
- refs/tags/*-RELEASE
In the Azure DevOps Service, the yaml build just trigger current branch, such as the .yml file in the dev branch, and add Push trigger trigger - master, then push code in the master branch, it will not trigger the build.
As a workaround, we need to update the .yml content in the different branch.
For example, If we create YAML build in the master branch, it will create azure-pipelines.yml file in the master branch.
Should trigger pipeline on master branch if PR is merged to master branch
Should trigger pipeline on master branch if git tag is added on master branch.
We can do this by adding the following push triggers
trigger:
batch: true
branches:
include:
- master
tags:
include:
- refs/tags/*-RELEASE
Should not trigger pipeline if git tag is added on non-master branches (like develop, features branches)
Should trigger pipeline on non-master branches if PR is merged or commit happens on these branches
Then create branch develop and features, it also contain the file azure-pipelines.yml, edit the file content.
trigger:
batch: true
branches:
include:
- develop #in the develop enter develop, in the feature branch, we need to update it to feature.
tags:
exclude:
- refs/tags/*-RELEASE
Update1

Azure DevOps - Batching using multi-repo trigger

I've tried multi repo trigger using azure devops.
resources: repositories:
- repository: ToolsRepo
name: ToolsRepo
type: git
trigger:
batch: true
branches:
include:
- master
trigger does not work. It works only if I remove batch: true line. How could I make it work together with batching?
According to the test result, if you set batch: true to other repos (not the repo where the current yaml pipeline file is located), then CI trigger from other repos will not trigger the pipeline.
The CI trigger from the current repo can trigger the pipeline normally.
So I am afraid that batch: true is currently not supported in multi-repo trigger. In addition, the batch argument is not specified in the multi-repo trigger yaml syntax.
You could add your request for this feature on our UserVoice site, which is our main forum for product suggestions. The product team would provide the updates if they view it. Thank you for helping us build a better Azure DevOps.

Resources