Jenkins插件-环境变量 [英] Jenkins plugin - environment variables
问题描述
我正在将Jenkins与Testswarm和此插件(分叉源).
I am using Jenkins with Testswarm and this plugin (forked sources).
我想为Testswarm获得一个工作名称",其中包含詹金斯的工作名称,内部版本号和svn修订号.
I want to get a "job name" for Testswarm containing the Jenkins job name, build number and svn revision number.
在配置字段中放入JOB_NAME没有帮助,该变量不会被其值替换.
Putting JOB_NAME in the configuration field does not help, the variable is not replaced by its value.
因此,我修改了插件源代码以获取Jenkins环境变量,但我得到的只是空".
So I modified the plugin source code to get the Jenkins environment variables but all I get are "null"s.
这是罪魁祸首. (在第205行的src/main/java/com/javaclimber/jenkins/testswarmplugin/TestSwarmBuilder.java中)
Here is the culprit code. (in src/main/java/com/javaclimber/jenkins/testswarmplugin/TestSwarmBuilder.java from line 205)
我对此功能进行了大量研究,但没有找到获取变量的有效示例.
I researched a lot concerning this functionnality and I did not find a working example for getting a variable.
public boolean perform(AbstractBuild build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException {
...
EnvVars envVars = build.getEnvironment(listener);
...
envVars.get("JOB_NAME")
}
我在使用Java时不自在,因此我陷入了困境. 有人知道吗?
I am not at ease in Java and I am stuck at this point. Any idea anyone, please ?
更新:java使用的版本
Java版本"1.6.0_24"
OpenJDK运行时环境(IcedTea6 1.11.5)(6b24-1.11.5-0ubuntu1〜10.04.2)
OpenJDK 64位服务器VM(内部版本20.0-b12,混合模式)
Update: java used version
java version "1.6.0_24"
OpenJDK Runtime Environment (IcedTea6 1.11.5) (6b24-1.11.5-0ubuntu1~10.04.2)
OpenJDK 64-Bit Server VM (build 20.0-b12, mixed mode)
推荐答案
替换
EnvVars envVars = build.getEnvironment(listener);
通过
EnvVars envVars = new EnvVars();
envVars = build.getEnvironment(listener);
成功了...
这篇关于Jenkins插件-环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!