Inject env vars to Jenkins programmatically

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Inject env vars to Jenkins programmatically

nirk
Hi,

I am trying to inject environment variables to Jenkins build from my internal Maven plugin in Java. 

What did I do? 

I added the Jenkins code Maven dependency to my plugin an implemented the relevant interface: 


public class Test implements EnvironmentContributingAction{

       @Override

    public void buildEnvironment(Run<?, ?> run, EnvVars env) {

                EnvironmentContributingAction.super.buildEnvironment(run, env);

    }  
 
}


Now - I'm trying to call this class from a different class: 

EnvVars envVars = new EnvVars();

envVars.put("myvar", "myvalue");

Test test = new Test();

test.buildEnvironment(???? , envVars);



What is the "Run" class? What should I add into this method so it will run from the build object in Jenkins? 

Any Github example or snippet will be much appreciated.

Thanks,
Nir

This message may contain confidential and/or privileged information. 
If you are not the addressee or authorized to receive this on behalf of the addressee you must not use, copy, disclose or take action based on this message or any information herein. 
If you have received this message in error, please advise the sender immediately by reply email and delete this message. Thank you.

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/21f2f0c6-fafe-42e8-a5c3-31d939646726%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.