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

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

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:

References

Have more questions?

0 Comments

Please sign in to leave a comment.