Azure pipeline will not trigger from a branch with a single azure-pipelines.yml file - azure

I've recently set up an Azure pipeline using the following azure-pipelines.yml file in the master branch:
trigger:
- master
- feature/*
pool:
vmImage: 'ubuntu-latest'
variables:
buildConfiguration: 'Release'
steps:
- script: dotnet build --configuration $(buildConfiguration)
displayName: 'dotnet build $(buildConfiguration)'
I've also tried these two syntax examples for the trigger to no avail as well as removing the trigger completely.
trigger:
branches:
include:
- master
- feature/*
trigger:
branches:
include: ['*']
I've linked this to a GitHub repo where I created a branch called feature/cool_feature.
According to all of the docs I've read, I should be able to place the YAML file in the master branch which should start a build for both my branches. But all I can get this to do is start a build when a commit is made in the master branch.
The only want I could get the build to trigger is if I put another azure-pipelines.yml file inside of that branch.
Is this no longer the case or am I doing something wrong?

Apparently, you must have another copy of the master's azure-pipelines.yml file in the branch for this to work.

Related

How do I set up PR validations in Azure DevOps/GitHub?

We are migrating from Azure DevOps to GitHub and we have Build Validations set up where if you make a change in a specific folder, the respective CI pipeline will run when a PR is created.
I am trying to make use of the PR triggers in my YAML file, however when I open a PR it doesn't seem to work.
My pipeline is:
trigger: none
pr:
branches:
include:
- develop
- release/*
- ProductionSupport/*
paths:
include:
- cicd/pipelines/common/pre-commit-ci.yaml
- src
- cicd
pool:
vmImage: ubuntu-latest
variables:
PRE_COMMIT_HOME: $(Pipeline.Workspace)/pre-commit-cache
steps:
- bash: echo "##vso[task.setvariable variable=PY]`python -V`"
displayName: Get python version
- task: Cache#2
inputs:
key: pre-commit | .pre-commit-config.yaml | "$(PY)"
path: $(PRE_COMMIT_HOME)
- bash: |
pip install --quiet pre-commit
pre-commit run
displayName: 'Run pre-commit'
As a test to make sure my branches/paths were correct I updated the triggers section to:
trigger:
branches:
include:
- develop
- release/*
- ProductionSupport/*
paths:
include:
- cicd/pipelines/common/pre-commit-ci.yaml
- src
- cicd
Then when I made a change in one of the files in these folders, the pipeline was successfully triggered. Am I specifying my PR validation incorrectly?
Your yml definition seems correct.
Since you mentioned the CI trigger work fine and you mentioned We are migrating from Azure DevOps to GitHub.
This brings me a idea that a situation that exactly reproduces what you're experiencing and you might not expect:
PR Trigger Override
For example, if your pipeline is the same one as before(Just change the pipeline source), and you didn't delete the previous build validation(Or previous pipeline name is same as the current one), then the pr part in your github yml file will be override, only the build validation on DevOps side will work.
I suggest you investigate whether you have some build validation settings to the pipeline(If your project structure is complex, this maybe difficult to find) or you can simply create a totally new pipeline with the new YAML file.

Migrating azure-pipelines.yaml to separate repo, but running on code of other repo

Ultimately, I'm trying to do this:
Move azure-pipelines.yaml and associated templates out of the code repository (code-repo).
Move them into a separate dedicated repository (pipeline-repo).
Have the pipeline look at the config for the pipeline in pipeline-repo, but run the pipeline on the code in the code-repo.
I'm referring the following documentation:
Use other repositories: this one refers to "templates in other repositories," but I'm trying to remove any pipeline configs so the code-repo is just purely application code... and the Dockerfile.
Define a repositories resource
For testing, I have this simple test.yaml:
# Triggers when PR is created due to branch policies
trigger: none
resources:
repositories:
- repository: code-repo
type: git
name: code-repo
pool:
vmImage: 'ubuntu-latest'
stages:
- stage: Testing
displayName: Test stage
jobs:
- job: ParallelA
steps:
- bash: echo Hello from parallel job A
displayName: 'Run a one-line script'
When I create a PR on code-repo, it is triggering the pipeline, which is to say branch policies are configured to refer to that pipeline. I do get the print out the Hello from parallel job A print out.
But I don't see in the run logs it pulling code-repo.
I do see the following, however:
My actual PR pipeline would look something like this:
trigger: none
resources:
repositories:
- repository: code-repo
type: git
name: code-repo
variables:
- template: templates/variables.yaml
pool:
vmIMage: $(vmImageName)
stages:
- template: templates/build/buildStage.yaml
...
Testing that, it confirms that it isn't running on the code-repo PR, but the pipeline-repo so everything fails.
So it is unclear to me what I need to do from here to get the pipeline to run on the PR code from code-repo.
Suggestions?
Ok, I think I have it sorted out, at least some of my stages are now succeeding.
I came across this documentation which informed me of checkout.
So in addition to doing something like:
resources:
repositories:
- repository: code-repo
type: git
name: code-repo
Then you need to add a step called checkout like the following:
# Triggers when PR is created due to branch policies
trigger: none
resources:
repositories:
- repository: code-repo
type: git
name: code-repo
pool:
vmImage: 'ubuntu-latest'
stages:
- stage: Testing
displayName: Test stage
jobs:
- job: ParallelA
steps:
- checkout: code-repo
- task: task1
- task: task2
The checkout should set the context for the subsequent steps.

Trigger a pipeline when specific file is changed

I am creating a new CI pipeline that will be triggered anytime a .bicep file is changed and then zip up all of the files.
# Pipeline is triggered anytime there is a change to .bicep files
trigger:
branches:
include:
- "feature/*"
pool:
vmImage: ubuntu-latest
steps:
- script: echo Hello, world!
displayName: 'Run a one-line script'
This pipeline works and is triggered anytime a change is made in the feature branch.
To target any .bicep files I am trying:
trigger:
branches:
include:
- "feature/*"
paths:
include:
- '**/*.bicep'
I also tried to specify the entire route that holds the files:
trigger:
branches:
include:
- "feature/*"
paths:
include:
- "src/Deployment/IaC/Bicep/*"
When I make a change to a .bicep file in the feature branch, the pipeline is never triggered so I know my syntax is wrong.
Wildcards are not supported anymore for azure pipelines.
Instead just set the relative path to your Bicep folder like so :
paths:
include:
- src/Deployment/IaC/Bicep
see : https://learn.microsoft.com/en-us/azure/devops/pipelines/repos/azure-repos-git?tabs=yaml&view=azure-devops#paths

Azure DevOps unable to trigger yaml pipeline off of completed build

I can't get my yaml pipeline to trigger based off the build completion of another pipeline.
This is the code from the yaml pipeline I am trying to trigger to run, where pipelineX is the name of the pipeline build I want the run to trigger off of:
resources:
pipelines:
- pipeline: trigger-pipeline
source: pipelineX
trigger: true
steps:
- task: Bash#3
inputs:
targetType: 'inline'
script: |
echo 'pipeline runs here'
Both pipelines are part of the same project, so that should not be an issue.
I have similar setup with my project. I am triggering 'PipelineNeedsTrigger' build based on successful build of 'PipelineTriggerFrom' pipeline. Both pipelines are under the same project. I have exported my YAML and added snippet here which might help you. I have added below trigger into my 'PipelineNeedsTrigger' which will trigger once the 'PipelineTriggerFrom' has successful build on 'master' branch. This might help you link.
resources:
pipelines:
- pipeline: PipelineTriggerFrom
source: PipelineTriggerFrom
trigger:
branches:
include:
- refs/heads/master

Azure DevOps - two dependent YAML pipelines in one repository

I have two .yml files in my repo. One for build, one for deployment. The main reason why I would like to keep build separate from the deployment is that I also would like to store variables for environments in my repo, e.i. in variables-dev.yml and variables-prod.yml files. So there is no need to create a new build every time (which includes running tests, docker image build etc.).
The file build.yml:
trigger:
paths:
exclude:
- build.yml
- deploy.yml
stages:
- stage: build
jobs:
...
And the deploy.yml, which I want to be triggered only on the completion of the build pipeline. That's why I add the first exclusion of all paths, but add one on pipeline resource.
trigger:
paths:
exclude:
- '*'
resources:
pipelines:
- pipeline: build
source: build
trigger:
branches:
include:
- '*'
stages:
- stage: dev
variables:
- template: variables-dev.yml
jobs:
- deployment: deploy_dev
environment: 'dev'
strategy:
runOnce:
deploy:
steps:
...
- stage: prod
dependsOn: dev
variables:
- template: variables-prod.yml
jobs:
- deployment: deploy_prod
environment: 'prod'
strategy:
runOnce:
deploy:
steps:
...
Unfortunately it does not seem to work. The top trigger blocks lower trigger. And if I remove the top trigger than the deploy pipeline is triggered at the same time with the build one.
you have to start your deploy.yml with trigger: none
trigger: none
resources:
pipelines:
- pipeline: ci-pipeline
source: my-build-pipeline
trigger:
enabled: true
branches:
include:
- master
Set your triggers for the second yml to none, then add this setting in the "Triggers" section of the UI. It will stage your builds as you describe

Resources