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)
- CloudBees CI (CloudBees Core) on modern cloud platforms - Managed Master
- CloudBees CI (CloudBees Core) on modern cloud platforms - Operations Center
- CloudBees CI (CloudBees Core) on traditional platforms - Client Master
- CloudBees CI (CloudBees Core) on traditional platforms - Operations Center
- CloudBees Jenkins Enterprise
- CloudBees Jenkins Enterprise - Managed Master
- CloudBees Jenkins Enterprise - Operations Center
- CloudBees Jenkins Team
- CloudBees Jenkins Platform - Client Master
- CloudBees Jenkins Platform - Operations Center
- Github Plugin
- External Notification Plugin
- 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://wiki.jenkins.io/display/JENKINS/Git+Plugin
}
}
}
}
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
Tested product/plugin versions
The latest update of this article has been tested with:
- CloudBees CI (CloudBees Core) Managed Master 2.150.3.2
- notification-api 1.1
- pipeline-event-step 1.3
- operations-center-notification 1.0
0 Comments