Jenkins / Hudson plugin extension to set a pair of environment variables

I am expanding an existing Jenkins / Hudson plugin. I would like for him to set a couple of environment variables to run the project. What is the easiest way to do this?

+6
source share
3 answers

During assembly, for example, in Builder perform() , you can at least do this:

 @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 key-value pairs as build parameters, which will also display as environment variables in the usual way. Note. I have not tested it extensively, maybe some kind of “gotcha” that manifests itself in some situation ... But it has worked for me so far.

+7
source

Use the EnvInject plugin. You can create environment variables before starting the task or do it as a build step.

+1
source

You can use the EnvironmentContributor extension point, see http://javadoc.jenkins-ci.org/hudson/model/EnvironmentContributor.html

0
source

Source: https://habr.com/ru/post/895074/


All Articles