[workflow-plugin] Hack to unstash outside of a node block?

50 views
Skip to first unread message

Brian Ray

unread,
Oct 30, 2015, 12:40:02 PM10/30/15
to Jenkins Users
The unstash step outside of a node block is illegal, because it wants a workspace to unstash to:

node('planners') {

 
// ...
 
// do a bunch of stuff then stash the product
  stash
( name: 'plans', includes: 'plans/*' )

}

// this is unwrapped and will throw a MissingContextVariableException
unstash
'plans'

Is there a hack to unstash files out into the main workflow, or an equivalent that doesn't use stash and unstash? I'm attempting to offload some of the planning and preparation for downstream flow logic into the planners pool at the top of the flow. The main workflow would then use that output to split out chunks of work via parallel.

Brian Ray

unread,
Nov 6, 2015, 2:44:24 PM11/6/15
to Jenkins Users
Here's the hack. The example assumes I don't need the files as such in the main workflow, just the contents:

def planNumberOne
node
('planners') {

 
// ...
 
// slurp up the file and pass it "outside" the block
  planNumberOne
= readFile 'plans/plan_1'

}

// Lo and behold, the override sticks back out here in the main flow.
// This variable is not null, it has the contents of plans/plan_1 and
// the echo displays them.
echo planNumberOne

I did not expect it to work nor understand why it works. I knew you could pass an outer workflow variable into the node block but thought this was a one-way street. Ie that the block could see the value and possibly override it, but that the workflow would retain the original value.
Reply all
Reply to author
Forward
0 new messages