I Would Like to Use the GitHub Webhook Json file to Launch Relevant Pipeline Builds

Article ID:360017861992
2 minute readKnowledge base

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

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

Tested product/plugin versions

The latest update of this article has been tested with: