Environmental values from a Groovy Pipeline.

29 views
Skip to first unread message

Peter Berghold

unread,
Nov 30, 2017, 3:48:15 PM11/30/17
to Jenkins Users
I am most interested in using the "WORKSPACE" value in the enviromental values. within my pipeline..  I use it as a base to create a staging directory from so I have a value defined such as:

def outrepo="${env.WORKSPACE}/shipping-${env.BUILD_NUMBER}"

what I am getting back from that is not what I'm expecting at all. 

OUTREPO: null/shipping-152

Looks like env.WORKSPACE is being resolved as a "null" instead of the full path to the job's workspace. 

Is there a different form of this I should be using?  I clearly see WORKSPACE as being defined when within a shell I see that value running the shell command "env."

I could hard code it I supposed, but that kind defeats the purpose a bit....

Björn Pedersen

unread,
Dec 1, 2017, 1:19:13 AM12/1/17
to Jenkins Users
Hi,

it depends on where in your code you are trying to use this. A workspace is only available (and the  env set) while inside a node or ws block. And beware, when different parts of the pipeline run on different node, then each
part has it's own workspace, possibly even at different locations.  And unless there are strong requirements for absolute pathes,  better just use relative pathes (all steps will by default have the WORKSPACE as current working dir).

Björn

Peter Berghold

unread,
Dec 1, 2017, 12:55:55 PM12/1/17
to jenkins...@googlegroups.com
sounds like that was what bit me.   I'm seeing bizarre behavior all over the place that now makes sense given what you said about node {} 

--
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-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/ff698027-6d29-476c-b04b-ac2397561c9e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages