So I try to change a value in the .env file from within the pipeline and then directly commit it to the source branch, but new commits to the source branch retrigger the pipeline. Now my goal is to keep the pipeline run going and NOT retrigger it when only the .env file is changed. I tried excluding the file with paths like this:
trigger:
batch: true
branches:
include:
- main
- develop
paths:
exclude:
- '**/.env'
The .env is in the frontend folder, I also tried frontend/.env
, didn't work either. I also tried with this additionally:
pr:
branches:
include:
- main
- develop
paths:
exclude:
- VHS.TicketMachine.Frontend/.env
In my commit message made from the pipeline, it does ad [skip ci], but that doesn't do anything. Here is the modification:
- script: |
sed -i "s/^VITE_APP_VERSION=.*/VITE_APP_VERSION=$(buildVersion)/" .env
cat .env
git config user.name "Azure DevOps CI Pipeline"
git config user.email "[email protected]"
SOURCE_BRANCH=$(echo $(System.PullRequest.SourceBranch) | sed 's|refs/heads/||')
echo "Source branch: $SOURCE_BRANCH"
git fetch origin $SOURCE_BRANCH
git checkout $SOURCE_BRANCH
git add .env
git commit -m "Update VITE_APP_VERSION to $(buildVersion) [skip ci]"
git push https://$(System.AccessToken)@[redacted] $SOURCE_BRANCH
displayName: Set Frontend Version
workingDirectory: $(frontendDir)
As soon as the commit is made, the pipeline runs recursively, causing infinite runs. I would appreciate it very much if someone could be of help, thank you!
So I try to change a value in the .env file from within the pipeline and then directly commit it to the source branch, but new commits to the source branch retrigger the pipeline. Now my goal is to keep the pipeline run going and NOT retrigger it when only the .env file is changed. I tried excluding the file with paths like this:
trigger:
batch: true
branches:
include:
- main
- develop
paths:
exclude:
- '**/.env'
The .env is in the frontend folder, I also tried frontend/.env
, didn't work either. I also tried with this additionally:
pr:
branches:
include:
- main
- develop
paths:
exclude:
- VHS.TicketMachine.Frontend/.env
In my commit message made from the pipeline, it does ad [skip ci], but that doesn't do anything. Here is the modification:
- script: |
sed -i "s/^VITE_APP_VERSION=.*/VITE_APP_VERSION=$(buildVersion)/" .env
cat .env
git config user.name "Azure DevOps CI Pipeline"
git config user.email "[email protected]"
SOURCE_BRANCH=$(echo $(System.PullRequest.SourceBranch) | sed 's|refs/heads/||')
echo "Source branch: $SOURCE_BRANCH"
git fetch origin $SOURCE_BRANCH
git checkout $SOURCE_BRANCH
git add .env
git commit -m "Update VITE_APP_VERSION to $(buildVersion) [skip ci]"
git push https://$(System.AccessToken)@[redacted] $SOURCE_BRANCH
displayName: Set Frontend Version
workingDirectory: $(frontendDir)
As soon as the commit is made, the pipeline runs recursively, causing infinite runs. I would appreciate it very much if someone could be of help, thank you!
If you are using Azure Repos (git repositories hosted in Azure DevOps), then the pr
trigger has no effect. The pr
trigger is for GitHub hosted repositories only.
For your continuous integration trigger, remove the batch
setting as this can interfere with [skip ci]
.
If you have a build validation policy enabled, ensure that the exclusions are added to the path filters of the branch policy.
Alternatively, you could use conditions on the script that pushes changes to the repo to prevent endless triggers:
- script: |
..
condition: |
and(
ne(variables[‘build.reason’], ‘PullRequest’),
contains(variables[‘build.sourceversionmessage’], ‘[skip ci]’)
)
As general advice, I tend to avoid committing changes into the repo from a CI pipeline whenever possible. In your scenario where you are checking the source branch name into an .env file, won’t the source branch always be the branch that you are compiling? This would make more sense as a compile time activity used to produce a build artifact from the current commit.
batch: true
? – Rui Jarimba Commented Jan 8 at 14:13