Karthik Vee
Karthik Vee

Reputation: 85

Jenkins unable to fetch changeId and revisionId

I have configured and integrated Jenkins and Gerrit with Gerrit Trigger Plugin and as part of postbuild task in Jenkins i am executing following script:

/opt/sputnik/bin/sputnik --conf /opt/sputnik/myconf.properties --changeId $GERRIT_CHANGE_ID --revisionId $GERRIT_PATCHSET_REVISION
echo "exit 0 workaround"

Here is what sputnik is:https://github.com/TouK/sputnik

But Iam getting following output:

[PostBuildScript] - Execution post build scripts.
[PostBuildScript] - Resolving environment variables for the script content.
[PostBuildScript] - Evaluating the script: 
/var/lib/jenkins/sputnik/bin/sputnik --conf /var/lib/jenkins/sputnik/gerrit.properties --changeId $GERRIT_CHANGE_ID --revisionId $GERRIT_PATCHSET_REVISION
echo "exit 0 workaround"

[project1] $ /bin/sh -xe /tmp/hudson6990025050616459512.sh
+ /var/lib/jenkins/sputnik/bin/sputnik --conf /var/lib/jenkins/sputnik/gerrit.properties --changeId --revisionId
Sputnik version 1.7.0
Sputnik - review your Gerrit patchset with Checkstyle, PMD and FindBugs
usage: sputnik [--apiKey <apiKey>] [--buildId <buildId>] [--changeId <changeId>] --conf <conf> [--pullRequestId
   <pullRequestId>] [--revisionId <revisionId>]
--apiKey <apiKey>                 Optional API key for using Sputnik for Github
--buildId <buildId>               Optional build id for using Sputnik for Github
--changeId <changeId>             Gerrit change id
--conf <conf>                     Configuration properties file
--pullRequestId <pullRequestId>   Stash pull request id
--revisionId <revisionId>         Gerrit revision id
Missing argument for option: changeId
Build step 'Execute a set of scripts' changed build result to FAILURE
Build step 'Execute a set of scripts' marked build as failure
Finished: FAILURE

Upvotes: 2

Views: 1115

Answers (1)

Thurs
Thurs

Reputation: 186

The problem is caused by this security patch for Jenkins - it applies to versions 1.651.2, 2.3 and later. Here's a list of affected plugins.

Basically it forbids plugins to inject parameters not explicitly configured for build, hence your Jenkins doesn't know about $GERRIT_CHANGE_ID and $GERRIT_PATCHSET_REVISION.

According to Gerrit Trigger Plugin creators' notice:

As a workaround you can add the following JAVA_ARG to your jenkins configuration

-Dhudson.model.ParametersAction.keepUndefinedParameters=true

However, I find this solution too invasive so I came up with another fix. Simply add these string parameters to the job configuration:

  • GERRIT_CHANGE_ID

  • GERRIT_PATCHSET_REVISION

And that's it. Now your config should look like this:

Job parameters

Upvotes: 2

Related Questions