I have a simple question but unfortunately, I couldn’t find it searching! And I am a newbie in CircleCI and coding so feel free to explain plain things.
I am using config.yml version 2 for our automated deployment using CircleCI integrated with Bitbucket. I want to know how can I recognize which events from Bitbucket triggered the pipeline? for example was it Push, PR update, or Merge? I have already selected my desired webhooks in the Bitbucket setting.
So in simple words, I need to do something like this in my config.yml:
if [ $event == "PR_updated" ];
Any bits of help or ideas would be really appreciated.
Welcome to Discuss and great question – this is a bit of a tricky one!
To clarify some details, we don’t have a specific event type variable in CircleCI, we receive the webhook and it contains commit details. However, there could be some ways to check for this information.
We will automatically set a variable called CIRCLE_PULL_REQUEST if the commit that triggered the build is associated with an open Pull Request.
With the above in mind, you could at the very least tell if the commit is associated with a PR with something like:
name: If associated with PR
if [ -n "$CIRCLE_PULL_REQUEST" ]; then
echo "This is part of a PR!"
echo "This isn't part of a PR!"
Alternatively, if the above doesn’t work, you could modify your processes on your end for merging in PR’s and merging to open PR’s to include specific information or key identifier in the commit subject.
You could then use the API endpoint I mentioned to parse out (likely with jq) the commit details and look for specific matchings in order to proceed with a specific part of the script.
Hopefully the above helps and please let me know if you have any further questions!
Thanks for your reply and help.
For my exact situation, it works fine now. I wanted it to:
1- Run deploy to the DEV server whenever one of our team members approves a pull request from Bitbucket (unfortunately CircleCI doesn’t take action on approving PR event from Bitbucket, even though I removed the created PR from webhooks and Approve is the first event in its kind) so we have to make an Update on PR and CircleCI does take action on it. (So not bad for a start)
2- Run deploy to the Staging server whenever someone merges this PR to the master branch.
Using the > CIRCLE_PULL_REQUEST in the if then else block which you mentioned helped me executing different scripts for deployment to different environments.
For other scenarios, I will definitely need to go for the API endpoints as a beginner
Can you please suggest any simple tutorial to start with APIs?
Thanks a million.