Jenkins 无法获取 changeId 和 revisionId
Jenkins unable to fetch changeId and revisionId
我已经配置并集成了 Jenkins 和 Gerrit 与 Gerrit 触发器插件,作为 Jenkins 中构建后任务的一部分,我正在执行以下脚本:
/opt/sputnik/bin/sputnik --conf /opt/sputnik/myconf.properties --changeId $GERRIT_CHANGE_ID --revisionId $GERRIT_PATCHSET_REVISION
echo "exit 0 workaround"
人造卫星是这样的:https://github.com/TouK/sputnik
但我得到以下输出:
[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
问题是由 Jenkins 的 this security patch 引起的 - 它适用于版本 1.651.2
、2.3
及更高版本。
这是 list of affected plugins.
基本上它禁止插件注入没有为构建明确配置的参数,因此你的 Jenkins 不知道 $GERRIT_CHANGE_ID
和 $GERRIT_PATCHSET_REVISION
.
根据Gerrit Trigger Plugin creators' notice:
As a workaround you can add the following JAVA_ARG to your jenkins configuration
-Dhudson.model.ParametersAction.keepUndefinedParameters=true
但是,我发现此解决方案过于具有侵入性,因此我想出了另一个修复方法。只需将这些字符串参数添加到作业配置中:
GERRIT_CHANGE_ID
GERRIT_PATCHSET_REVISION
就是这样。现在您的配置应如下所示:
我已经配置并集成了 Jenkins 和 Gerrit 与 Gerrit 触发器插件,作为 Jenkins 中构建后任务的一部分,我正在执行以下脚本:
/opt/sputnik/bin/sputnik --conf /opt/sputnik/myconf.properties --changeId $GERRIT_CHANGE_ID --revisionId $GERRIT_PATCHSET_REVISION
echo "exit 0 workaround"
人造卫星是这样的:https://github.com/TouK/sputnik
但我得到以下输出:
[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
问题是由 Jenkins 的 this security patch 引起的 - 它适用于版本 1.651.2
、2.3
及更高版本。
这是 list of affected plugins.
基本上它禁止插件注入没有为构建明确配置的参数,因此你的 Jenkins 不知道 $GERRIT_CHANGE_ID
和 $GERRIT_PATCHSET_REVISION
.
根据Gerrit Trigger Plugin creators' notice:
As a workaround you can add the following JAVA_ARG to your jenkins configuration
-Dhudson.model.ParametersAction.keepUndefinedParameters=true
但是,我发现此解决方案过于具有侵入性,因此我想出了另一个修复方法。只需将这些字符串参数添加到作业配置中:
GERRIT_CHANGE_ID
GERRIT_PATCHSET_REVISION
就是这样。现在您的配置应如下所示: