There are a few possible options:
1. Add [skip ci]
to your git commit message
Whenever you change the bitbucket-pipelines.yml
on its own, add "[skip ci]" (without quotes) somewhere in your Git commit message. This will prevent the pipeline from running when you push to the Bitbucket remote.
Sources and more info:
Advantages:
Disadvantages:
- You have to remember to manually write the
"[skip ci]"
text. It's easy to forget, or perhaps a new team member will not know about it.
2. Use a Git Hook to automatically modify your git commit message
Write a Git Hook script that will automatically insert the "[skip ci]" text into the Git commit message. The script will have to do something like this:
- After a local commit, check the latest commit to see which files were changed. Use something like
git diff --name-only HEAD~0 HEAD~1
- If
bitbucket-pipelines.yml
was the only file changed, modify the commit to insert "[skip ci]"
into the commit message.
More info about Git Hooks:
Advantages:
- It's fully automatic. No need to manually tag your commit messages.
Disadvantages:
3. Make the bitbucket-pipelines.yml
check for the file changes
Add a section in the yml
build script to check which file was changed in the latest commit.
The script in the yml will have to do something like this:
- Check the latest commit to see which files were changed. Use something like
git diff --name-only HEAD~0 HEAD~1
- If
bitbucket-pipelines.yml
was the only file changed, abort the CI build immediately, with an exit 0
statement.
Advantages:
- It's fully automatic. No need to manually tag your commit messages.
- No need to write Git Hook scripts.
Disadvantages:
- The Docker image of your CI build will take 1-5 minutes to load, and then abort itself. This is a bit ineffecient and it will consume some of your build minutes.
- Because the CI build will still run for a few minutes, it will pollute your CI build history with build runs that didn't do anything.
4. Use a Conditional Step with "changesets" and "includePaths"
Define a changesets
with an includePaths
to execute a step only if one of the modified files matches the expression in includePaths
.
pipelines:
default:
- step:
name: build-frontend-artifact
condition:
changesets:
includePaths:
# only xml files directly under resources directory
- "src/main/resources/*.xml"
# any changes in frontend directory
- "src/site/**"
script:
- echo "Building frontend artifact"
Source and more info: