Azure DevOps run build on branch creation - azure-devops

My pipeline looks like:
trigger:
branches:
include:
- release-*
jobs:
- job: release
condition: contains(variables['Build.SourceBranch'], 'refs/heads/release-')
pool:
vmImage: 'windows-latest'
steps:
- bash: |
echo "RELEASE"
displayName: 'release_task1'
How can I make it executed automatically when new release-.. branch is created?

How can I make it executed automatically when new release-.. branch is created?
This is a limitation of YAML trigger.
If the yaml file is not present in the new create branch, the build will not be triggered.
That is reason why it does not execute automatically when creating a new release ... branch.
To resolve this issue, we need to create the yaml file in the basic branch, like release-basic, then we create a new branch based on the branch release-basic. Now the build will be executed automatically.
Hope this helps.

Related

I can't get the Azure Devops trigger to work

I will try to explain in the best way.
First situation: I didn't find any task to insert my yml file which is in ruby. If I choose Ruby, I can't edit the yaml file. If I can edit that file, I should make this trigger fire. It actually fires, not with the yml file I want
If I use the other way I can't save because I don't have permission to run pr on the master branch. My pipeline doesn't run automatically just manually
enter image description here
enter image description here
My yml:
# Ruby
# Package your Ruby project.
# Add steps that install rails, analyze code, save build artifacts, deploy, and more:
# https://learn.microsoft.com/azure/devops/pipelines/languages/ruby
trigger:
branches:
include:
- homolog_gso
pool:
vmImage: 'ubuntu-latest'
steps:
- task: UseRubyVersion#0
inputs:
versionSpec: '>= 2.5'
- script: |
gem install bundler
bundle install --retry=3 --jobs=4
displayName: 'bundle install'
- script: bundle exec cucumber -t #incluir_setor_resp_em_branco
displayName: 'bundle exec cucumber'
- task: PublishTestResults#2
inputs:
testResultsFormat: 'NUnit'
testResultsFiles: '**/TEST-*.xml'
mergeTestResults: true
searchFolder: '$(Common.TestResultsDirectory)'
testRunTitle: 'Regression Test Geocall Gab'
When creating a new YAML pipeline and selecting the provided template to generate a initialized YAML file, by default this YAML file will be saved into the default branch of source repository (such as master, main).
If you do not have the permissions to directly edit files in the default branch, you are surely not able to edit the YAML file saved in the default branch.
you should copy / create the YAML to another branch where you have the permissions to edit files (e.g. homolog_gso). Then create a PR to merge the changes from this branch to the default branch.
About the PR trigger in your case, you can set the PR trigger like as below in the YAML file from the homolog_gso branch:
pr:
branches:
include:
- master
. . .
By this way, if you push some changes to the homolog_gso branch and then create a PR to merge the changes to the master branch, the PR trigger will fire to run the YAML pipeline.

Azure DevOps branching and build deploy strategy

I'm working on the web services project on the Azure DevOps. I have written the yaml pipeline for build and release.
Currently I have kept the yaml file in Develop branch and created the pipeline job from same. As per the practice, we have two branches - Master & Develop. So how I can use single pipeline job for both the branches with auto trigger for develop and schedules base for main branch ? What is the best practice to build and deploy the code to DEV, UAT and PROD environments for Development and Master branches?
Update:
You need to make sure the yaml file that the pipeline use exists in both master and Develop, otherwise the commit will not trigger the pipeline at all.
1, pure yaml trigger settings in one pipeline.
azure-pipeline.yml in Master branch:
trigger:
- none
schedules:
- cron: "53 7 * * *"
displayName: Master Schedule
branches:
include:
- master
always: true
pool:
name: default
steps:
- script: echo Hello, world!
displayName: 'Run a one-line script'
azure-pipeline.yml in Develop branch:
trigger:
- Develop
pool:
name: default
steps:
- script: echo Hello, world!
displayName: 'Run a one-line script'
2, pure UI settings in one pipeline.
Original Answer:
You can override the CI trigger of your pipeline.
Pipeline of develop branch:
Pipeline of master branch:

How can i trigger a build in Azure DevOpswhen a pull request is made in Github

I'm using Azure DevOps for pipelines and GitHub as my repo. I want to trigger a build in Azure DevOps when a pull request is made.
I have two branches in GitHub: master and test.
When I update test and create a pull request I want Azure DevOps to automatically build the pipeline and run it... how can i do this ?
I tried the below but nothing happens
pr:
main
trigger:
main
pool:
vmImage: ubuntu-latest
You can add a pr trigger in your yaml pipeline:
pr:
- master
this worked for me in the end :
**pr:
branches:
include:
- '*'**
pool:
vmImage: ubuntu-latest
steps:
- script: echo Hello, world!
displayName: 'Run a one-line script'

Trigger Azure pipeline when new branch is created in releases/*

We want to adopt Trunk Based Development branching policy as explained here.
As a part of our solution we want to trigger Azure pipeline whenever a new release branch is created from master (trunk): for example releases/R.1
Our current yaml for said pipeline looks like this:
trigger:
branches:
include:
- releases/*
...
Unfortunately it doesn't trigger when branch is created. I suspect it will trigger when we make changes to release branch, but according to Trunk Based Development we plan to only merge cherry-picked bugfixes/hotfixes from master. Is there a way to trigger pipeline on branch creation?
Refer to this doc: Behavior of triggers when new branches are created
Here is the behavior when you push a new branch (that matches the branch filters) >to your repository:
If your pipeline has path filters, it will be triggered only if the new branch has >changes to files that match that path filter.
If your pipeline does not have path filters, it will be triggered even if there are >no changes in the new branch.
To trigger the pipeline when a new branch created, you need to remove the path filter and only set branch filter.
For example:
trigger:
- release/*
pool:
vmImage: ubuntu-latest
steps:
- script: echo Hello, world!
displayName: 'Run a one-line script'

How to create a CI Trigger on a different Azure Repo than where the YAML pipeline resides?

I want my YAML in one repo RepoA and my code to build in RepoB. How do I configure the YAML to have a CI Trigger on the code RepoB only?
Note: these repos are in the same Azure DevOps project.
The YAML is in the default branch (master) of RepoA. I've seen that people have had issues with CI triggers if the pipeline is not in the default branch.
Here is the azure-pipeline.yml contents:
trigger: none
resources:
repositories:
- repository: RepoB
type: git
name: RepoB
ref: master
trigger:
- master
pool:
vmImage: 'windows-latest'
steps:
- checkout: RepoB
I also tried removing the line
trigger: none
to see if that would work. The build will then start as soon as I save the yaml, as I would expect, but not when I make a change to RepoB master.
Then I tried the following and many more guesses, but nothing ever enabled a CI Trigger on RepoB. That is, the pipeline never ran when I would make commits to the master branch in RepoB.
resources:
repositories:
- repository: RepoB
type: git
name: RepoB
ref: master
trigger:
branches:
include:
- master
pool:
vmImage: 'windows-latest'
steps:
- checkout: RepoB
Here is what I see when I look at the pipelines triggers in the Azure Pipelines UI. Should I see a trigger for RepoB?
Update 1:
Although these were not my original settings, I have updated the settings to be as open as possible (no limits). I then tried the following:
I committed a file to the branch in RepoB. No CI trigger occurred.
Deleted the pipeline, and recreated. I committed a file to the branch in RepoB. CI Trigger finally occurred!
I believe this is a bug because none of these settings should limit this scenario for the following reasons:
Both of the repos are in the same Project.
RepoB is explicitly referenced in the pipeline.
Also, you shouldn't have to delete and recreate a pipeline in order for a setting to take effect.
UPDATE 2:
I narrowed it down to this Organization or Project level setting: Limit job authorization scope to referenced Azure DevOps repositories
The documentation of this setting does not mention CI Triggers at all, but I do not think that it should affect this scenario regardless, because the repo is referenced explicitly.
Doc References:
https://learn.microsoft.com/en-us/azure/devops/pipelines/process/access-tokens?view=azure-devops&tabs=yaml#limit-job-authorization-scope-to-referenced-azure-devops-repositories
https://learn.microsoft.com/en-us/azure/devops/pipelines/repos/azure-repos-git?view=azure-devops&tabs=yaml#limit-job-authorization-scope-to-referenced-azure-devops-repositories
I believe this is a bug and I have reported it here:
https://developercommunity2.visualstudio.com/t/yaml-pipeline-ci-trigger-for-repository-resource-i/1314241
Azure DevOps enables some limitation to access to resources by default. Please check if this project enables below options in Project Settings page.
Testing in my side that if these options are enabled, this issue can be reproduced. Thus please disable them, and create a new yaml pipeline. The new yaml pipeline should work as expected.
See: Access repositories, artifacts, and other resources for details.
I used your yaml and all works (the only difference is that I have main not master branch)
trigger: none
resources:
repositories:
- repository: RepoB
type: git
name: azure-functions
ref: main
trigger:
- main
pool:
vmImage: 'windows-latest'
steps:
- checkout: RepoB
On this screen you have a trigger which fires for a change done on RepoB