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<https://groups.google.com/forum/?fromgroups=#!searchin/jenkinsci-dev/parametersaction/jenkinsci-dev/-WcPTB6bR9Y/h0maKoW0RoMJ>
  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<http://jenkins.361315.n4.nabble.com/Plugin-dev-Builder-and-the-exporting-of-environment-variables-tt394181.html#a394182>
 , 
I see that Kohsuke 
Kawaguchi<http://jenkins.361315.n4.nabble.com/template/NamlServlet.jtp?macro=user_nodes&user=120869>
 "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

Reply via email to