简体   繁体   English

在Jenkins插件中设置envvars

[英]Setting envvars in Jenkins plugin

I'm trying to develop new Jenkins plugin. 我正在尝试开发新的Jenkins插件。 I've started from hello-world archetype provided by Jenkins. 我从詹金斯提供的hello-world 原型开始。 My plugin works fine! 我的插件正常工作!

Bun now i want to put some environment variables from my plugin. 包子现在我想从我的插件中放入一些环境变量。 I've used whis code to do it 我用代码来做到这一点

public void perform(Run<?, ?> run, FilePath workspace, Launcher launcher, TaskListener listener) {

    ...
    EnvVars envVars = run.getEnvironment(listener);
    envVars.put("SOME_VARIABLE", "SOME_VALUE");
    ...

}

But it don't work. 但这不起作用。 I'm trying to use this variable on next build step and got nothing. 我正在尝试在下一个构建步骤中使用此变量,但一无所获。 I've googled it and there isn't quite clear discriptions. 我已经用谷歌搜索了,没有很明确的描述。 Source codes of existing plugins (EnvInject, etc) also doesn't help. 现有插件的源代码(EnvInject等)也无济于事。

What am i doing wrong? 我究竟做错了什么? Can anybody provide me some samples? 有人可以给我一些样品吗?

From my plugin... 从我的插件...

 private void putEnvVar(String key, String value) throws IOException {
     Jenkins jenkins = Jenkins.getInstance();
     DescribableList<NodeProperty<?>, NodePropertyDescriptor> globalNodeProperties = jenkins.getGlobalNodeProperties();
     List<EnvironmentVariablesNodeProperty> envVarsNodePropertyList = globalNodeProperties.getAll(hudson.slaves.EnvironmentVariablesNodeProperty.class);

     EnvironmentVariablesNodeProperty newEnvVarsNodeProperty = null;
     EnvVars envVars = null;

     if (envVarsNodePropertyList == null || envVarsNodePropertyList.isEmpty()) {
        newEnvVarsNodeProperty = new hudson.slaves.EnvironmentVariablesNodeProperty();
        globalNodeProperties.add(newEnvVarsNodeProperty);
        envVars = newEnvVarsNodeProperty.getEnvVars();
     } else {
        envVars = envVarsNodePropertyList.get(0).getEnvVars();
     }
     envVars.put(key, value);
  }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM