Hi,
I am trying to write a plugin that will be called several times during a build with different options set. During the first call, I would like to set several parameters that will be used during subsequent calls. In this thread I found the helpful suggestion to use
build.addAction(new ParametersAction(new StringParameterValue("MY_NEW_PARAM","my_new_param_value")));
This does add MY_NEW_PARAM=my_new_param_value to the environment, and I can see it via
EnvVars env=new EnvVars();
env = build.getEnvironment(launcher.getListener());
System.out.println(env.toString());
However, I do not see it in the build's parameters.
ParametersAction parameters = build.getAction(ParametersAction.class);
List<ParameterValue> paramList=parameters.getParameters();
System.out.println(paramList.toString());
During subsequent calls to my plugin during a build, I still see the new param in the environment, but do not see it in the parameter list, and do not see it in the parameters summary when the build is done.
Another approach:
In this thread , I see that Kohsuke Kawaguchi "added EnvironmentContributingAction as a generalization of ParametersAction, so that you can contribute environment variables from arbitrary Actions."
However I have not had much luck finding many clues about how to implement it.
I tried this:
EnvVars myenv=new EnvVars();
myenv.put("TEST_PARAM", "PARAM_VALUE");
EnvironmentContributingAction ea=build.getAction(EnvironmentContributingAction.class);
ea.buildEnvVars(build, myenv);
System.out.println(myenv.toString());
env=build.getEnvironment(launcher.getListener());
System.out.println(env.toString());
And it looks like ea.buildEnvVars(build, myenv); does add the build's params to myenv, but not the other way around, which is what I was looking for.
I'm not a java expert, I'm just a build guy who is desperately trying to get Jenkins to play nice with some of our proprietary tools so that I can convince our team to adopt Jenkins, so please go easy on me. A short code snippet would be a huge, huge help.
Thanks,
-Dave