Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,365,000
Community Members
 
Community Events
168
Community Groups

Execute pipeline only if specific piece of config is changed in commit

Hello,

I'm trying to create Bitbucket Pipeline which will be executed only if some specific config is changed in commit. 

For example, we have this piece of config in config.yml

someKey:
  value: string
anotherKey:
  anothervalue: number
hdp:
  version: 1.0.0

and I want to execute aws cli within bitbucket pipeline only if that version number is modified in commit, nothing else. Something like

if version value is modified in commit
then
  some aws cli
  exit 0
else
  echo "no relevant changes pushed"
  exit 1
fi

 Is it possible directly with some condition in pipeline? If not, can it be done with bash?

I can image it could be done with git show and if version is mentioned in last commit, then my pipeline will be executed, but I would like to avoid using git is possible.

Thank you

1 answer

1 accepted

1 vote
Answer accepted
Patrik S Atlassian Team Oct 20, 2021

Hello @Vladimír Jančich ,

Thank you for reaching out to Atlassian Community!


Unfortunately, there’s no native pipeline condition that will trigger the build based on a specific content of the commit files.

Currently, the only condition supported in pipelines is changesets, where you can define the file/folder name patterns that will trigger a given step. In case you would like to read more about changesets, you can find detailed information on Configure bitbucket-pipelines.yml documentation :

 

With that in mind, I can think of three workarounds that may help you to proceed further:

1. Use the latest commit content to decide whether to proceed with the build step: 

You may use the following command :

    if ! [[ $(git show -Gversion --quiet --pretty=%H) ]];then exit 0; fi;


    If the commit content did not add/remove/edit a line that contains the word “version”, Pipeline build will exit the build step and return 0 with exit code.

    Only the build step that ran the exit 0 code will be exited, the next steps will be executed as usual. In other words, you have to either add the condition to every step you want to skip or make your pipeline a single step.

    The pipeline will be normally triggered accordingly to your current setting, meaning that even in commits that don't change the version, the build minutes used to check the conditions will still be decreased against your quota.

 

2. Create a new tag that will only be used to trigger the build, such as hdpversion. You can read more about tag-specific build pipeline on Configure Bitbucket Pipelines 

 

3. Run a pre-configured build manually on a specific branch with Pipelines' "custom" keyword
:

Run pipelines manually - Atlassian Documentation 

 

Also, I raised an enhancement request asking for this functionality, which you can check on the link below :

https://jira.atlassian.com/browse/BCLOUD-21435

Our development team will give a first-hand update through that ticket if there's any progress made so I would suggest keeping a watch and vote for it.
Do note however that there's no ETA on enhancement requests, and all enhancements are implemented with this policy in mind:
https://confluence.atlassian.com/support/implementation-of-new-features-policy-201294576.html
Let us know if you have any questions.

 

Best Regards,
Patrik S
Atlassian Support Engineer

Suggest an answer

Log in or Sign up to answer
TAGS

Atlassian Community Events