jenkinsci / generic-webhook-trigger-plugin

Can receive any HTTP request, extract any values from JSON or XML and trigger a job with those values available as variables. Works with GitHub, GitLab, Bitbucket, Jira and many more.
https://plugins.jenkins.io/generic-webhook-trigger
404 stars 159 forks source link

the plugin couldn't catch the variable that configured in environment part of declarative pipeline #196

Closed shenmou98 closed 3 years ago

shenmou98 commented 3 years ago

Hello,

when I set generic webhook in declarative pipeline like below code,
in regexpFilterExpression, it can't catch the variable "ci_branch " that I configured in enviroment, regexpFilterExpression will get a finally value: refs/heads/null , the expected value should be refs/heads/master And by the way , if the variable configured in pipeline parameters , regexpFilterExpression can get the correct value. And, if use some jenkins built in variables such as env.JOB_NAME, it also culd get the correct value.

I think this may be a bug. Hope your help, Thanks.

` ......

parameters {
    string(name: "action", defaultValue : "toBuild", description: "something")
}

environment { 
    ci_branch = "master"
}

triggers {
    GenericTrigger(
    genericVariables: [
        [key: 'branch', value: '$.ref', expressionType: "JSONPath"],
        [key: 'repository', value: '$.repository.full_name', expressionType: "JSONPath"]
    ],

    causeString: "Auto deployed ",

    token: 'ServiceTempQA',
    tokenCredentialId: '',

    printContributedVariables: true,
    printPostContent: true,

    silentResponse: false,

    regexpFilterText: '$branch',
    regexpFilterExpression: 'refs/heads/' + env.ci_branch
    )
}

...... `

shenmou98 commented 3 years ago

Maybe because in jenkins, the generic-webhook-trigger-plugin pipeline content load before environment ? If this is true, I think it didn't make sense. because user may want to use some self environment variables in generic-webhook-trigger-plugin.

shenmou98 commented 3 years ago

The reason I want to use variable in environment , is because in envronment variable, I can have some shell like below (the branch come from the jenkins job name) : for example, the jenkins job name is group_my-project_master_QA ci_branch = sh(script: 'echo ${JOB_NAME} | cut -d "_" -f 3', , returnStdout: true).trim() # ci_branch will be master

so I can have different jenkins job for different github branch, and they can share the same generic-webhook-trigger-plugin pipeline content.

tomasbjerre commented 3 years ago

I don't think this can be solved in this plugin. Perhaps you should try opening an issue here: https://www.jenkins.io/participate/report-issue/

shenmou98 commented 3 years ago

I don't think this can be solved in this plugin. Perhaps you should try opening an issue here: https://www.jenkins.io/participate/report-issue/

Hi @tomasbjerre , I know little about Jenkins's plugin mechanism, could you pelase explain more?

tomasbjerre commented 3 years ago

The input to the plugin contains the null value. The null value is resolved before the plugin is involved.

shenmou98 commented 3 years ago

The input to the plugin contains the null value. The null value is resolved before the plugin is involved.

@tomasbjerre but the other pipeline stages could get the correct environment variable , such as the below code, it can print the correct value of ci_branch.

stages { stage("Prepare") { steps { echo "ci_branch: ${ci_branch}" } } }

shenmou98 commented 3 years ago

And I also created the jenkins issue https://issues.jenkins.io/browse/INFRA-2854