Trigger azure pipeline based on multiple file changes - azure-devops

I'm trying to trigger an Azure DevOps Build pipeline based on two files being changed simultaneously on my master repository, with the following trigger:
trigger:
branches:
include:
- master
paths:
include:
- '**/*task.json'
- '**/vss-extension.json'
My folder structure for this repository is something like this:
repository:
|--run-stryker
--vss-extension.json
--other files here ...
|--task
--task.json
--other files here ...
Yet changes to these files at the same time are not triggering my pipeline. What am I doing wrong here?

Unfortunately using wildcards like this in CI triggers is not supported at this moment. You can use * only at the end of paths but this is working the same as without this.
Wildcards like this are working in file matching in tasks but not in path trigger. So you must use exact paths like:
trigger:
branches:
include:
- master
paths:
include:
- 'run-stryker/task/task.json'
- 'run-stryker/vss-extension.json'
or using only folder paths like:
trigger:
branches:
include:
- master
paths:
include:
- 'run-stryker/*' # is the same as 'run-stryker/'
Documentation reference: Wildcards in CI triggers

Related

How to combine trigger filters in azure pipeline?

I have a CD pipeline, which uses a CI pipeline as a resource. In my CD pipeline, I have triggers that exclude some project paths that I have in the solution, in my resource I have included my main branch on the trigger.
CD pipeline:
trigger:
branches:
include:
- main
paths:
exclude:
- src/Customer.Worker.Converter
pool:
vmImage: "ubuntu-latest"
resources:
pipelines:
- pipeline: customer-ci
source: Customer-API-CI
trigger:
branches:
include:
- main
stages:
...
What I want to happen is when I push from my main branch, the CI pipeline runs and activates the CD pipeline only when what I changed is not in the paths I excluded from the trigger, in this case, when I change something in the Customer.Worker.Converter project, I don't want this pipeline to be triggered.
But even when I change something from path Customer.Worker.Converter, the CD pipeline triggers after the CI pipeline, ignoring my exclude path trigger and apparently obeying the CI resource pipeline trigger I use.
Is there any way to get what I want using pipeline resource?
As per this article, you've defined two separate triggers, but I think you only want one when the CI pipeline completes. At the moment, you will trigger changes based on the CI pipeline and when there are code-pushes.
If you only want the CD pipeline to be triggered when the CI pipeline completes, change the trigger for the CD pipeline to be none:
# ci pipeline
trigger:
branches:
include:
- main
paths:
include:
- src/Customer.Worker.Converter/*
----
# cd pipeline
resources:
pipelines:
- pipeline: customer-ci
source: customer-api-ci
trigger:
branches:
include:
- main # only trigger the CD pipeline when the CI pipeline on 'main' completes.
# do not trigger changes to this pipeline when code-changes are made
trigger: none
In theory, you can combine resource triggers:
When filters are specified, the source pipeline run must match all of the filters to trigger a run.
So one possibility would be to configure the cd pipeline to only run when the CI pipeline completes on the main branch and has a specific tag.

to Trigger one pipeline after another and also triggered by every changes

I have 2 pipelines. i need B pipeline to run after A pipeline completes and I also need B pipeline to triggers by Every test branch changes. I am not sure if using resources and trigger at the same file (B pipeline) is correct?
trigger:
batch: true
branches:
include:
- test
resources:
pipelines:
- pipeline: A
source: A
trigger: true
Test the scenario, it works as expected.
If that doesn't work, then please try to add the pipeline yaml file to Test branch, then create the pipeline B from Existing Azure Pipelines YAML file.
trigger:
batch: true
branches:
include:
- Test
resources:
pipelines:
- pipeline: A # Any Alias
source: A # The real pipeline name
project: Basic # Project name if from another project within the same org
trigger:
branches:
include:
- refs/heads/master

Azure DevOps : excluding updates to yaml pipeline files from triggering those same pipelines?

Somehow I'm not getting how I can exclude updates yaml pipelines from trigger the pipelines themselves. I have tried some wildcards as described here both in the include item (with the ! operator) or in the exclude item and nothing worked. I've added the plain pipeline names with no wildcards in the excluded item and again it did not work. The yaml files sit in the root of my repository (no containing folder).
These don't work
trigger:
branches:
include:
- MyBranch
paths:
exclude:
- "*.yml"
- "**/*.yml"
Clearly adding the full name of the pipeline works but you can't always edit exisitng yaml files each and every time you add a new one
If you don’t want to trigger the pipeline when updating azure-pipelines.yml file, you can set the following trigger:
trigger:
branches:
include:
- master
paths:
exclude:
- /azure-pipelines.yml
I'm confused, with the following syntax CI pipelines are not triggered when updating *.yml files
trigger:
branches:
include:
- MyBranch
paths:
include:
- '!**/*.yml'
while with the following one (which as I understand it should mean the same thing as the above one) pipelines keep being triggered when updating any *.yml file
trigger:
branches:
include:
- MyBranch
paths:
exclude:
- "**/*.yml"
What am I not getting?

non-interference pipeline triggers between 2 azure pipelines

I have 2 pipelines named as a.yml & b.yml. Both of them are under the folder cci-project/xyz-lable-service/devOps/
How can I create a following pipeline trigger
for pipeline a.yml it will be triggered by branch update except pipeline b.yml
for pipeline b.yml it will be only triggered by if anything updated in the b.yml file
for pipeline a.yml it will be triggered by branch update except pipeline b.yml
We could use the Branches and Paths trigger like following in the a.yml:
trigger:
branches:
include:
- master
- Dev
paths:
exclude:
- b.yml
for pipeline b.yml it will be only triggered by if anything updated in
the b.yml file
We could only set the path trigger include the b.yml file in the b.yml:
trigger:
paths:
include:
- b.yml
You could check this document for some more details.
Hope this helps.

Using Lerna.js and Azure Devops Pipeline

I'm studying about azuredevops pipelines to a new project. I'm totally new about devops.
In this project, I want to use lerna.js to manage my monorepo and my packages.
Considering that I have those three projects inside my monorepo:
Package 1 (1.0.1)
Package 2 (1.0.0)
Package 3 (1.0.3)
And I want to create a new TAG, which will increase the Package 3 to (1.0.4). How can I trigger an Azure Pipeline just to Package 3? There is any guide?
I watched one talk about monorepos with lerna.js and I'm trying to figure out if Azure Pipelines has one feature similar to what Sail CI does. In the exemple we have this approch:
tasks:
build-package-1:
image: sailci/demo
when:
paths:
- "packages/package-1/**/*"
The company I'm working at is using Azure DevOps, would be awesome know if I can have that feature there.
The closest thing similar to that one is like #Simon Ness wrote multiple pipelines with path filters. Additionally if your packages have similar strucutre and require the same steps to creeate/test/publish package you should consider templates.
The conspet toi handle packages like you described can be similar to below steps.
template.yaml
parameters:
- name: workingDir
type: string
default: package-1
steps:
- script: npm install
workingDiretory: ${{ parameters.workingDir }}
- script: yarn install
workingDiretory: ${{ parameters.workingDir }}
- script: npm run compile
workingDiretory: ${{ parameters.workingDir }}
then pipeline for Package-1 may look like this:
trigger:
branches:
include:
- master
- releases/*
paths:
include:
- Package-1/*
steps:
- template: templates/template.yaml
parameters:
workingDir: Package-1
and for Package-2:
trigger:
branches:
include:
- master
- releases/*
paths:
include:
- Package-2/*
steps:
- template: templates/template.yaml
parameters:
workingDir: Package-2
EDIT
For tag part all you need to do is change trigger section:
trigger:
branches:
include:
- master
- refs/tags/*
and when you create a tag and push it:
git tag release-05
git push origin --tags
your pipeline wil start:
However, trigger works like or condition, so for any change on master or new tag piepline will start. So if you tag another branch (not master) pipeline will start.
This is why you may need to check if your source branch is the one from trigger section:
trigger:
branches:
include:
- master
- refs/tags/*
stages:
- stage: A
condition: eq(variables['Build.SourceBranch'], 'master')
jobs:
- job: JA
steps:
- script: |
echo "This is job Foo."
Above pipeline will run for:
change in master branch
any tag pushed to server, but it runs stage A only if you push tag to master branch
If you're happy to define a separate pipeline for each package take a look at paths in CI triggers.
Tags can be used as a trigger by including the branch - refs/tags/* in the triggers section.