I am extending an existing Jenkins/Hudson plugin. I would like it to set a environment variable pair for the running project. What is the easiest way to do that?
Under Build Environment check Set environment variables through a file. give the path of that file here. If the environment variable is created in the first job then again you can save all the environment variable in a file and browse it using the above method. Install this plugin and go to job configuration paeg.
We can set global properties by navigating to “Manage Jenkins -> Configure System -> Global properties option”.
During build, for example in a Builder
's perform()
method, you can do at least 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 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With