Cleanup workspace before/after build

331 views
Skip to first unread message

Sverre Moe

unread,
Oct 11, 2018, 3:33:23 AM10/11/18
to Jenkins Users
This deleteDir() does not always work on a Windows build slave.

Using Scripted PIpeline I am declaring a node within try-catch-finally.
The finally will run deleteDir(), in order to delete the build workspace. This is done in order to get a fresh build each time. I cannot risk having stale data lying around from a previous builds.

Is there some other means I can make sure that the build has a clean workspace?

1) Always build with clean
mvn clean deploy
gradle clean build publish

2) SCM configuration
Clean after checkout
Clean before checkout

3) Windows working deleteDir()

Baptiste Mathus

unread,
Oct 11, 2018, 4:02:54 AM10/11/18
to jenkins...@googlegroups.com
What is the JIRA number number for the Windows deleteDir() bug you say you're seeing? 

--
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/966a8838-f95a-4c23-ac61-e4c7356fac8d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Andreas Tscharner

unread,
Oct 12, 2018, 7:35:36 AM10/12/18
to jenkins...@googlegroups.com
Hi Sverre,

On 11.10.2018 09:33, Sverre Moe wrote:

[snip]
> Is there some other means I can make sure that the build has a clean
> workspace?

Our Windows agents are virtual machines that get reset to a certain
snapshot to make sure they are clean.

Best regards
Andreas
--
Andreas Tscharner sterne...@gmail.com

Gordon's Law:
If you think you have the solution, the question was poorly phrased.

Sverre Moe

unread,
Oct 12, 2018, 11:41:22 AM10/12/18
to Jenkins Users
I will see if I can find some more information about the problem.

Sverre Moe

unread,
Oct 12, 2018, 11:43:34 AM10/12/18
to Jenkins Users
fredag 12. oktober 2018 13.35.36 UTC+2 skrev Andreas Tscharner følgende:
Hi Sverre,

On 11.10.2018 09:33, Sverre Moe wrote:

[snip]
> Is there some other means I can make sure that the build has a clean
> workspace?

Our Windows agents are virtual machines that get reset to a certain
snapshot to make sure they are clean.
 
To reset the Windows VM after each build seems like a heavy operation. It could take a while to reset to a snapshot, and in the mean time other builds might be waiting.

Sverre Moe

unread,
Nov 12, 2018, 9:03:03 AM11/12/18
to Jenkins Users
Hi,

Sorry, I completely forgot to respond.

I'm not sure if there is an existing reported JIRA bug for this.
Not sure when this fix was release. It does seems like we are running with it according to the exception it throws. I recall getting a different exception previosuly before I added the try-catch surrounding the deleteDir.

My scripted pipeline
node(nodeName) {
    unstash
'archive'
    sh
"tar -zxf ${projectName}.tar.gz"

   
try {
        tool name
: 'gradle-4.8', type: 'gradle'
        sh
"gradle ${javaOptions} --refresh-dependencies ${buildTask} ${releaseProperty} -Pheadless"

        stash allowEmpty
: true, includes: "build/**/*.rpm", name: stashName

       
/* Archive Linux FPM packages */
        archiveArtifacts allowEmptyArchive
: true, artifacts: "build/**/*.rpm", onlyIfSuccessful: true

       
/* Archive Windows native executables. */
        archiveArtifacts allowEmptyArchive
: true, artifacts: "build/**/*.exe", excludes: "build/**/${projectName}/*.exe", onlyIfSuccessful: true
   
} catch (e) {
       
throw e
   
} finally {
       
try {
            deleteDir
()
       
} catch (e) {
            println e
       
}
   
}
}


I had to wrap the deleteDir within a try-catch, because otherwise it would sometimes fail the build.
The downside is with this I sometimes get a workspace with pre-existing build artifacts.
        
java.io.IOException: Unable to delete 'C:\cygwin64\home\build\jenkins\workspace\application_sverre_work-3U54DPE57F6TMOZM2O6QBWDQ2LNRU2QHAXT6INC3UPGWF2ERMXAQ\build\deploy\package\windows\application.iss'. Tried 3 times (of a maximum of 3) waiting 0,1 sec between attempts.


torsdag 11. oktober 2018 10.02.54 UTC+2 skrev Baptiste Mathus følgende:
Reply all
Reply to author
Forward
0 new messages