Issue
-
I have a pipeline which uses a feature of the GitHub plugin which forces a workspace (like "ignore certain users", etc) but would like to not require a workspace
-
I have a pipeline which I would like to custom trigger based on certain conditions from a GitHub Webhook
Environment
-
CloudBees CI (CloudBees Core) on modern cloud platforms - Managed controller
-
CloudBees CI (CloudBees Core) on modern cloud platforms - Operations Center
-
CloudBees CI (CloudBees Core) on traditional platforms - Client controller
-
CloudBees CI (CloudBees Core) on traditional platforms - Operations Center
-
CloudBees Jenkins Enterprise
-
CloudBees Jenkins Enterprise - Managed controller
-
CloudBees Jenkins Enterprise - Operations center
-
notification-api
-
pipeline-event-step
-
operations-center-notification
Resolution
Follow the instructions explained in External HTTP Endpoints - example webhook event trigger.
Adapt the jmespathQuery
to match the json parsing requirements.
pipeline { agent any triggers { eventTrigger jmespathQuery("repository.name=='REPO_NAME'&&head_commit.author.username!='test_account'") } stages { stage('Example') { steps { sh 'echo "Git Commit: $GIT_COMMIT" has triggered a build' // More variables at https://plugins.jenkins.io/git/ } } } }
The above is for a declarative pipelines and if you want to use scripted then properties([pipelineTriggers([eventTrigger(jmespathQuery("repository.name=='REPO_NAME'&&head_commit.author.username!='test_account'"))])])
The JQ command I am doing there is matching the repo name(REPO_NAME) and ensuring the last commit was not written by test_account. The full Webhook API for github can be found here for what will be included in that json file and can be parsed with JQ