Setting envvars in Jenkins plugin

27 views
Skip to first unread message

Konstantin

unread,
Dec 28, 2017, 11:08:06 AM12/28/17
to Jenkins Developers

I'm trying to develop new Jenkins plugin. I've started from hello-world archetype provided by Jenkins. My plugin works fine!

Bun now i want to put some environment variables from my plugin. I've used whis code to do it

public void perform(Run<?, ?> run, FilePath workspace, Launcher launcher, TaskListener listener) {

    ...
    EnvVars envVars = run.getEnvironment(listener);
    envVars.put("SOME_VARIABLE", "SOME_VALUE");
    ...

}

But it don't work. I'm trying to use this variable on next build step and got nothing. I've googled it and there isn't quite clear discriptions. Source codes of existing plugins (EnvInject, etc) also doesn't help.

What am i doing wrong? Can anybody provide me some samples?

Daniel Beck

unread,
Dec 28, 2017, 11:18:07 AM12/28/17
to jenkin...@googlegroups.com

> On 28. Dec 2017, at 17:08, Konstantin <k.en...@gmail.com> wrote:
>
> But it don't work. I'm trying to use this variable on next build step and got nothing. I've googled it and there isn't quite clear discriptions. Source codes of existing plugins (EnvInject, etc) also doesn't help.

Not having looked at the code, you're probably getting your own copy of the EnvVars.

One of these should get you there:
https://jenkins.io/doc/developer/extensions/jenkins-core/#environmentcontributor
https://jenkins.io/doc/developer/extensions/jenkins-core/#buildwrapper
https://jenkins.io/doc/developer/extensions/jenkins-core/#runlistener

Reply all
Reply to author
Forward
0 new messages