I’m trying to use the new GitHub PR trigger feature described here:
(Why I can’t post links here?)
- CircleCI Discuss topic #52739
- CircleCI Discuss topic #52796
- circleci dot com slash docs slash github-trigger-event-options
What I ultimately want to do is trigger CircleCI via GitHub PR events (open, reopen, synchronize) and run SonarQube on the PR branch, when the PR is targeting (base.ref) is our main branch. Worth noting is main branch is not the default branch set on github. We got some weird branching scheme going on here.
What I’ve done is onboard the project to use Github App installation (our organization is on Github OAuth), add following events as trigger:
- All pushes
- PR marked ready for review
- Pushes to open non-draft PRs
- PR opened
All triggers are pointing to .circleci/config.yml
pipeline. I’m using [workflow level when
expression](circleci dot com slash docs slash config-reference hash using-when-in-workflows) to decide if we should run pr workflow or deployment workflows.
The information I need here is the base branch ref name in pipeline value for workflow run condition and passing into SonarQube. I’ve tried the following expressions:
pipeline.trigger_parameters.webhook.body.pull_request.base.ref == "main"
→ Compile error, variable doesn’t existpipeline.trigger_parameters.webhook.body
regex matches\"base\"\s*:\s*\{.*\"ref\"\s*:\s*\"main\"
→ Doesn’t trigger pipeline- echo
pipeline.trigger_parameters.webhook.body
in bash:{}
(I thought this should contain webhook body sent from github?) - echo
pipeline.trigger_parameters.github_app
→ Compile error, guess there’s no dot drilling logic in compiler - echo
pipeline.trigger_parameters.github_app.ref
in bash: returns head ref, not what I want - echo
pipeline.trigger_parameters.github_app.checkout_sha
in bash: compile error, but this value is documented in [pipeline values table](circleci dot com slash docs slash variables hash pipeline-values)? - echo
pipeline.git.base_revision
in bash: Empty string
I could identify pipeline triggers from pull request via pipeline.event.name == "pull_request"
[documented here](circleci dot com slash docs slash github-trigger-event-options hash supported-trigger-options), even though it’s not in pipeline values table.