Hey folks,

I'd like to understand how Jenkins Pipeline allocates workspaces - I'm 
alarmed that subsequent node {} elements in a Jenkinsfile appears to 
allocate the same workspace. It's causing problems with conflicting or 
missing files. My Jenkinsfile looks like this; 

    stage "Testing"

    node {
            // This will allocate a "default" workspace.
            writeFile file: "workspace_1st_node_block.txt", text: "${pwd()}"
    }

    node {
            // I think this *should* create another workspace, but it 
doesn't, it reuses the 1st workspace.
            writeFile file: "workspace_2nd_node_block.txt", text: "${pwd()}"
    }

    node { ws { 
            writeFile file: "workspace_subworkspace.txt", text: "${pwd()}"
    }}


When the build of this Jenksinfile completes, if I do a `tail` on the 
contents of these workspaces from the Jenkins master, it looks like this; 

    ==> workspace@2/workspace_subworkspace.txt <== 
    
/var/lib/jenkins/jobs/jamesread/jobs/testcase-jenkins-pipeline-workspaces-reuse/branches/master/workspace@2
 

    ==> workspace/workspace_1st_node_block.txt <== 
    
/var/lib/jenkins/jobs/jamesread/jobs/testcase-jenkins-pipeline-workspaces-reuse/branches/master/workspace
 

    ==> workspace/workspace_2nd_node_block.txt <== 
    
/var/lib/jenkins/jobs/jamesread/jobs/testcase-jenkins-pipeline-workspaces-reuse/branches/master/workspace


I would have expected 3 workspaces to be created, but instead just 2 were 
created (one by the 1st node{} declaration, one by the ws {} declaration). 
I've created this as a testcase in the following GitHub repo; 
https://github.com/jamesread/testcase-jenkins-pipeline-workspaces-reuse/ 

In my real project, I've resorted to wrapping each step in a "node { ws {" 
to force new workspaces to be created, but now it seems that even these 
workspaces are being reused! Just to restate, my questions are; 

1) Is workspace re-use expected, and I just have the wrong expectation? 

2) An ideal situation would be that the worksapces are ephemeral, and are 
deleted when the job completes. But I could not find a reliable way to do 
this yet in a Jenkinsfile. Is this possible?

Thanks. 

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-users/50964d32-ab2b-4db8-97af-bb23ed220905%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to