Jenkins plugin development - environment variables
Is it possible to get a map of the environment variables that are used in Jenkins? I'm trying to develop my own plugin and you need to access the BUILD_USER_ID variable that is provided by the vars build plugin.
There is an EnvVars class that inherits from TreeMap, but it is clearly empty if you instantiate this.
EnvVars env = new EnvVars();
Where are these variables stored so I can get them and use them in my plugin?
source to share
I expect you to mean the built-in variables injected by the Build User Vars Plugin into the build.
If you are interested in reading the configuration of static jobs (for example from a groovy script system) use job.getBuildWrappersList().get(org.jenkinsci.plugins.builduser.BuildUser.class)
to get a user configured BuildUser instance . In the case of building plugins for custom Vars, there are not many settings to read.
If you want to access the actual values of the variables entered into the build process (for example from BuildStep
), call build.getEnvironment(TaskListener)
to get a populated instance EnvVars
with all the variables. Note that these variables are not available outside of the assembly context.
source to share