Skip to content

Instantly share code, notes, and snippets.

@hughsaunders
Created March 15, 2017 08:51
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hughsaunders/3b4634d20de613d6d173340351449fd2 to your computer and use it in GitHub Desktop.
Save hughsaunders/3b4634d20de613d6d173340351449fd2 to your computer and use it in GitHub Desktop.
Jenkins nested node, how to find the first workspace
Started by user Hugh Saunders
[Pipeline] node
Running on rpc-jenkins-n02.prod.dfw1.cit.rackspace.net-9082c1d1 in /var/lib/jenkins/workspace/scratchpipeline
[Pipeline] {
[Pipeline] sh
[scratchpipeline] Running shell script
+ date
+ pwd
/var/lib/jenkins/workspace/scratchpipeline
+ ls
foo
[Pipeline] sh
[scratchpipeline] Running shell script
+ pwd
[Pipeline] node
Running on rpc-jenkins-n02.prod.dfw1.cit.rackspace.net-9082c1d1 in /var/lib/jenkins/workspace/scratchpipeline@2
[Pipeline] {
[Pipeline] sh
[scratchpipeline@2] Running shell script
+ cat foo
cat: foo: No such file or directory
[Pipeline] echo
node: Failed to find file foo
[Pipeline] ws
Running in /var/lib/jenkins/workspace/scratchpipeline@3
[Pipeline] {
[Pipeline] sh
[scratchpipeline@3] Running shell script
+ pwd
/var/lib/jenkins/workspace/scratchpipeline@3
+ ls
+ cat foo
cat: foo: No such file or directory
[Pipeline] }
[Pipeline] // ws
[Pipeline] echo
node+ws: Failed to find file foo
[Pipeline] sh
[scratchpipeline@2] Running shell script
+ cd /var/lib/jenkins/workspace/scratchpipeline
+ cat foo
Wed Mar 15 08:49:30 UTC 2017
[Pipeline] }
[Pipeline] // node
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
Finished: SUCCESS
node(){
sh "date > foo; pwd; ls"
nwd=sh(returnStdout: true, script: "pwd")
node(){
try{
sh "cat foo"
}catch (e){
echo "node: Failed to find file foo"
}
try{
ws(nwd){
sh "pwd; ls; cat foo"
}
}catch(e){
echo "node+ws: Failed to find file foo"
}
try{
sh """#!/bin/bash -x
cd ${nwd}
cat foo
"""
}catch(e){
echo "node+cd: Failed to find file foo"
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment