Use generic webhook trigger variables in pipeline

3.7k Views Asked by At

I am using the generic webhook plugin to trigger my builds: https://plugins.jenkins.io/generic-webhook-trigger/

In the settings of this plugin it allows you to define variables based on the content of the webhook. I use this to create variable like $name & $branch.

I can use these variables inside the trigger condition for the build (I use it to check the commit is for the right branch).

What I would really like to do is have access to the variables I define here inside my actual pipeline.

So I would be able to do something like:

steps {
        slackSend(channel: "#pipeline", message: 'Starting to build ${branch} for ${name}', botUser: true, color: 'good')
    }

How can I get these webhook variables into my build environment variables?

2

There are 2 best solutions below

2
mayurva On BEST ANSWER

Guerrilla answered this in a comment, but the fix is to use double quotes instead of single quotes as below:

steps {
    slackSend(channel: "#pipeline", message: "Starting to build ${branch} for ${name}", botUser: true, color: 'good')
}
4
Sourav On

Try this out:

steps {
    slackSend(channel: "#pipeline", message: 'Starting to build ${params.branch} for ${params.name}', botUser: true, color: 'good')
}