Hello @ismail !
It is possible to trigger a step by using trigger-pipline-actions, but it needs some modifications in your pipline steps.
Here’s an example workflow that basically triggers a build if PR is closed:
name: Trigger Buildkite Build if a PR is closed
on:
pull_request:
types: [closed]
jobs:
triggerBuildkite:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Trigger Buildkite Pipeline
run: |
curl -X POST "https://api.buildkite.com/v2/organizations/<your-org-slug>/pipelines/<your pipleine slug>/builds" \
-H "Authorization: Bearer ${{ secrets.BUILDKITE_API_TOKEN }}" \
-d '{
"commit": "HEAD",
"branch": "${{ github.head_ref }}",
"message": "Triggered by PR closing",
}'
The intent behind this file is to simply trigger a build if a PR is closed.
In your buildkite pipeline , you can levarge the use of conditionals and set a condition that would restrict the step to be trigered / cause the step to be triggered. In the following example pipeline, I’ve used the build.message
conditional atribute to play around with my pipline:
steps:
- label: "Run on PR close and Merge"
command: echo "Close and merge step is running"
if: build.message =~ /Triggered / || build.message =~ /Merge /
- label: "Run on Merge only"
command: echo "regular step is running"
if: build.message =~ /Merge /
And my pipeline settings are as follows:
In the above case, When you create a branch, a pipeline is uploaded, and as long as you ensure that you do not have a “Merge” or a “Triggered” keyword in your build message/commit message , no successive steps will run. And once you close a PR , the github actions will trigger a build with a message “Triggered by PR closing”. On buildkite side, this evaluates “if: build.message =~ /Triggered /” to true, and the respective step would be triggered.
When merged, build.message =~ /Merge / on both the steps will evaluate to true and will run both the steps.
Feel free to reach out if you require any further assistance, we’re here to help!
Cheers,
Athreya .