Discussion:
Cleanup workspace before/after build
Sverre Moe
2018-10-11 07:33:23 UTC
Permalink
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()*
--
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+***@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.
Baptiste Mathus
2018-10-11 08:02:33 UTC
Permalink
What is the JIRA number number for the Windows deleteDir() bug you say
you're seeing?
Post by Sverre Moe
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()*
--
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
To view this discussion on the web visit
https://groups.google.com/d/msgid/jenkinsci-users/966a8838-f95a-4c23-ac61-e4c7356fac8d%40googlegroups.com
<https://groups.google.com/d/msgid/jenkinsci-users/966a8838-f95a-4c23-ac61-e4c7356fac8d%40googlegroups.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
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+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/CANWgJS40Qbvn2Htd4US9nb8i6w_5O%2BFsvPvYZy%3D%2BfWZDdGZ2vg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Sverre Moe
2018-10-12 15:41:22 UTC
Permalink
I will see if I can find some more information about the problem.
Post by Baptiste Mathus
What is the JIRA number number for the Windows deleteDir() bug you say
you're seeing?
Post by Sverre Moe
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()*
--
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
To view this discussion on the web visit
https://groups.google.com/d/msgid/jenkinsci-users/966a8838-f95a-4c23-ac61-e4c7356fac8d%40googlegroups.com
<https://groups.google.com/d/msgid/jenkinsci-users/966a8838-f95a-4c23-ac61-e4c7356fac8d%40googlegroups.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
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+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/9ab3faf2-7918-4e6e-94e8-0edbb1ebc57e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Sverre Moe
2018-11-12 14:03:03 UTC
Permalink
Hi,

Sorry, I completely forgot to respond.

I'm not sure if there is an existing reported JIRA bug for this.
https://issues.jenkins-ci.org/browse/JENKINS-15331
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.
Post by Baptiste Mathus
What is the JIRA number number for the Windows deleteDir() bug you say
you're seeing?
Post by Sverre Moe
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()*
--
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
To view this discussion on the web visit
https://groups.google.com/d/msgid/jenkinsci-users/966a8838-f95a-4c23-ac61-e4c7356fac8d%40googlegroups.com
<https://groups.google.com/d/msgid/jenkinsci-users/966a8838-f95a-4c23-ac61-e4c7356fac8d%40googlegroups.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
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+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/60b50a51-2b75-4e4e-82bb-32d9f1dc99e1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Andreas Tscharner
2018-10-12 11:35:19 UTC
Permalink
Hi Sverre,

On 11.10.2018 09:33, Sverre Moe wrote:

[snip]
Post by Sverre Moe
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 ***@gmail.com

Gordon's Law:
If you think you have the solution, the question was poorly phrased.
--
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+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/b4220abc-d6b1-b60b-0c79-c33685364290%40gmail.com.
For more options, visit https://groups.google.com/d/optout.
Sverre Moe
2018-10-12 15:43:34 UTC
Permalink
Post by Andreas Tscharner
Hi Sverre,
[snip]
Post by Sverre Moe
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.
--
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+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/14c168c0-2a0b-430f-a7c4-dbc9988a2b54%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...