简体   繁体   English

Jenkins插件开发 - 环境变量

[英]Jenkins plugin development - environment variables

Is there any possibility to get a map of environment variables that are used in Jenkins? 有没有可能获得Jenkins中使用的环境变量的映射? I am trying to develop my own plugin and need to access the variable BUILD_USER_ID, which is provided by the build user vars plugin. 我正在尝试开发自己的插件,并且需要访问由build user vars插件提供的变量BUILD_USER_ID。

There is a class called EnvVars, which inherits from TreeMap, but it is obviously empty, if you create an object of this. 有一个名为EnvVars的类,它继承自TreeMap,但如果你创建了一个对象,它显然是空的。

EnvVars env = new EnvVars();

Where are these variables stored , so that I can get them and use them in my plugin? 这些变量存储在哪里,以便我可以获取它们并在我的插件中使用它们?

I expect you mean build variables injected by Build User Vars Plugin into build. 我希望你的意思是Build Build Vars Plugin注入构建变量。

If you are interested in reading static jobs configuration (from system groovy script for instance), use job.getBuildWrappersList().get(org.jenkinsci.plugins.builduser.BuildUser.class) to get user configured instance of BuildUser . 如果您对读取静态作业配置感兴趣(例如,从系统groovy脚本),请使用job.getBuildWrappersList().get(org.jenkinsci.plugins.builduser.BuildUser.class)来获取用户配置的BuildUser实例。 In case of Build User Vars Plugin there is not much configuration to read, though. 在Build User Vars Plugin的情况下,没有太多的配置可供阅读。

If you would like to access actual variable values injected into the build process (from a BuildStep for instance), call build.getEnvironment(TaskListener) to get populated EnvVars instance with all variables. 如果要访问注入构建过程的实际变量值(例如,来自BuildStep ),请调用build.getEnvironment(TaskListener)以获取包含所有变量的EnvVars实例。 Note that these variables are not available outside of build context. 请注意,这些变量在构建上下文之外不可用。

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

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