[英]Extending a Jenkins/Hudson plugin to set a environment variable pair
I am extending an existing Jenkins/Hudson plugin.我正在扩展现有的 Jenkins/Hudson 插件。 I would like it to set a environment variable pair for the running project.
我希望它为正在运行的项目设置一个环境变量对。 What is the easiest way to do that?
最简单的方法是什么?
During build, for example in a Builder
's perform()
method, you can do at least this:在构建期间,例如在
Builder
的perform()
方法中,您至少可以这样做:
@Override
public boolean perform(Build<?, ?> build, Launcher launcher, BuildListener listener)
throws InterruptedException, IOException {
//...
List<ParameterValue> params = new ArrayList<ParameterValue>();
params.add(new StringParameterValue(name1, value1));
params.add(new StringParameterValue(name2, value2));
build.addAction(new ParametersAction(params));
//...
}
It will add the key-value pairs as build parameters, which will be visible as environment variables too, in the usual manner.它将以通常的方式将键值对添加为构建参数,这些参数也将作为环境变量可见。 Note: I have not tested that extensively, there may be some "gotcha" which presents itself in some situation... But it has worked for me so far.
注意:我没有进行过广泛的测试,在某些情况下可能会出现一些“陷阱”......但到目前为止它对我有用。
You could use the EnvironmentContributor extension point, see http://javadoc.jenkins-ci.org/hudson/model/EnvironmentContributor.html您可以使用 EnvironmentContributor 扩展点,请参阅http://javadoc.jenkins-ci.org/hudson/model/EnvironmentContributor.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.