How does Jfrog Pipelines' GitRepo Include and Exclude files works? Which takes precedence? - jfrog-pipelines

I want to create a GitRepo resource in my pipelines but want to use combination of include and exclude files. But I am unclear on precedence!
If the pattern I give matches with both include and exclude - how does it work?
- name: platform_pr
type: GitRepo
configuration:
gitProvider: myGithub
path: dev/helm-values
files:
include: m*
exclude: ma*
branches:
include: ^master$
buildOn:
commit: true

The current behavior for GitRepo resource in pipelines is as follows:
Take all files impacted by the commit
Remove all files that DON'T match the included pattern
Remove all files that DO match the excluded pattern
If any files are left, the resource is updated

Related

Azure Devops pipelines - clone multiple repos by same tag or branch

I have three Azure Repos, all in the same ADO Project - repo-0001, repo-0002, repo-0003
repo-0001 has my yaml pipeline which has a manual trigger, and the pipeline needs to be run on demand by either branch or tag (eg release/branch001, release/tag001)
The Pipeline checkouts out repo-0001, repo-0002 & repo-0003 at whatever ref (branch or tag) is used to start the pipeline in repo-0001 (these branches & tags are created by a different process and are always present in all repos)
I've been using $(Build.SourceBranch) to extract:
branch - refs/heads/release/branch001
tag - refs/tags/release/tag001
This yaml works for a pipeline started using a branch, but not for a tag, and it results in Could not get the latest source version for repository repo-0001 hosted on Azure Repos using refs/heads/refs/tags/release/tag001 so it appears to append the whole ref path of the tag to refs/heads
variables:
REPOSITORY_SOURCE_BRANCH: $(Build.SourceBranch)
resources:
repositories:
- repository: repo-0001
type: git
name: aks/repo-0001
ref: $(REPOSITORY_SOURCE_BRANCH)
- repository: repo-0002
type: git
name: aks/repo-0002
ref: $(REPOSITORY_SOURCE_BRANCH)
- repository: repo-0003
type: git
name: aks/repo-0003
ref: $(REPOSITORY_SOURCE_BRANCH)
I can make it work with a tag by doing something like this, or passing in as a parameter
variables:
tag: "release/tag001"
resources:
repositories:
- repository: repo-0001
type: git
name: aks/repo-0001
ref: 'refs/tags/$(tag)'
etc
But that's not what I need...
Can a tag ref be passed in from pipeline variables to make this work, and is there a way to make it flexible so that I can use the same pipeline code for tags and branches?
Thanks!
The ref field in repositories Resources doesn't support defining Pipeline variable. It only supports hardcode the ref value.
Can a tag ref be passed in from pipeline variables to make this work, and is there a way to make it flexible so that I can use the same pipeline code for tags and branches?
To meet your requirement, you can change to use the following format to checkout the repo.
- checkout: git://MyProject/MyRepo#refs/tags/$(tag)
- checkout: git://MyProject/MyRepo#$(REPOSITORY_SOURCE_BRANCH)
Here is an example:
variables:
REPOSITORY_SOURCE_BRANCH: test
steps:
- checkout: git://aks/repo-0001#$(REPOSITORY_SOURCE_BRANCH)
For more detailed info, you can refer to this doc: Checking out a specific ref

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?

Trigger azure pipeline based on multiple file changes

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

Azure build pipeline path filter to only include particular file extension

I'm working on creating build pipeline in Azure DevOps. I want to trigger it against master branch but only when commit has changes under src/Project/tds/Serialization.Master/ Project - this project contains only .item files
If the commit includes any other files together with .item then this pipeline shouldn't trigger, tried path exclude
BDD
Scenario 1
Given | I've changes for src/Project/tds/Serialization.Master/*
Then | build pipeline should trigger
Scenario 2
Given | I've changes for src/Project/tds/Serialization.Master/*
And | I've changes for src/Foundation/*
Then | build pipeline shouldn't trigger
Scenario 3
Given | I've changes for src/Foundation/*
Then | build pipeline shouldn't trigger
trigger:
branches:
include:
- master
paths:
include:
- src/Project/tds/Serialization.Master/*
exclude:
- src/Foundation/*
Azure build pipeline path filter to only include particular file extension
If want to use path filter to trigger the build for those particular file-extension files in the folder Serialization.Master, you could use following syntax:
trigger:
paths:
exclude:
- src/Foundation/*
include:
- src/Project/tds/Serialization.Master/*
You could check the document YAML schema reference for some more details.
Note: Do not forget the keyword paths.

Concourse CI, git tag with constant value

I would like to tag my git commits as they are deployed to the various environments in my concourse pipeline with the name of the environment. For example, in my UAT deployment job, I would like to do something like:
- put: master-resource <-- a git resource
params:
repository: master <-- the resource local directory
tag: 'uat'
force: true <-- replace the tag, if it already exists
tag_only: true
This would seem like a common -or at least simple, thing to do however the value of the 'tag' parameter can only be the path to a file -there is no option to pass a constant/literal value.
I see two possible solutions but none of them seems 'simple' enough:
Create a file myself, but to do that (ideally?) I wish there were some kind of file resource that I could use to create the file.
The last alternative would be to create a custom task, and even there I was struggling to find a way to pass the name of the tag as a parameter.
Any suggestions on what would be the best way to accomplish my goal in the simplest way, or alternatively how to implement options 1 or 2?
Thanks!
The reason that tag takes in a file is so that you can dynamically set the tag of the commit based on information you imply during the course of the pipeline.
So, the best way I can see to do something like this would be workflow #2 that you described above.
So you would want something like this:
- task: generate-git-tag
params:
TAG: {{some-passed-in-tag}}
config:
platform: linux
image_resource:
type: docker-image
source:
repository: ruby
outputs:
- name: tag-file
params:
TAG:
run:
path: /bin/bash
args:
- -c
- |
echo "${TAG}" >> tag-file/tag.txt
- put: master-resource <-- a git resource
params:
repository: master <-- the resource local directory
tag: tag-file/tag.txt
force: true <-- replace the tag, if it already exists
tag_only: true