withEnv on parallel jobs

380 views
Skip to first unread message

Esdras Neto

unread,
Sep 1, 2017, 4:09:33 AM9/1/17
to Jenkins Users
Hi there,

I was using load to set my variables and it was working fine, however, this wont work with multiple jobs running in parallel.

How can I set a bunch of system variables using withEnv and reuse the code?

I tried:

def LNX_VARS = '''PATH=/path/to/ant/bin:/usr/bin:/sbin',
                             'JAVA_HOME=/path/to/my/java''''

And then:

withEnv (LNX_VARS) {
                      sh 'ant -v'

}

Is there any documentation about using multiple system variable lines with withEnv? 

Thanks!
Esdras


Esdras Neto

unread,
Sep 2, 2017, 2:50:32 PM9/2/17
to Jenkins Users
Still stuck here, is there a way to reuse blocks of code as variable in the pipeline?

I can see in the logs that the variable is passed, but we get errors like:
java.lang.NoSuchMethodError: No such DSL method 'withEnv(['

This time I tried to make a variable with the whole thing (not only the variables but the withEnv command as well).

Any light?

Thanks!

Baptiste Mathus

unread,
Sep 2, 2017, 10:40:48 PM9/2/17
to jenkins...@googlegroups.com
withEnv takes an array parameter.
So something like:

withEnv(['AAA=blah', 'BBB=bill]) {
    sh 'echo $AAA and $BBB'
}

Should work. Can't check easily now from the phone.

My 2 cents

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/f294dfc5-d44a-4d32-a277-db849c69c8fc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages