Hi,
I was struggling through the same type of issue and just got mine to work.  
Hope this helps

My plugin 'extends' Builder.  For this to work I had to create another 
class 'InjectVariable'

// This is called from the Builder class I wrote
build.addAction( new InjectVariable( "VERSION_TAG", "V1.2.3.4" ) );

public class InjectVariable implements EnvironmentContributingAction {
 private String key;
 private String value;

 public InjectVariable( String key, String value )
 {
 this.key = key;
 this.value = value;
 }

 @Override
 public String getIconFileName() {
 return null;
 }

 @Override
 public String getDisplayName() {
 return null;
 }

 @Override
 public String getUrlName() {
 return null;
 }

 @Override
 public void buildEnvVars(AbstractBuild<?, ?> build, EnvVars env) {
 if( env != null && key != null && value != null )Enter code here.

 {
 env.put(this.key, this.value);
 }
 }
 }

Enter code here...


On Wednesday, June 13, 2018 at 12:05:50 PM UTC-5, [email protected] 
wrote:
>
> 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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-dev/a344ef41-3e13-4b32-b8df-edd23642341e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to