Clean up after build using build flow plugin

32 views
Skip to first unread message

Katie Outram

unread,
Feb 24, 2015, 9:43:34 AM2/24/15
to jenkins...@googlegroups.com
After the build completes, I need to clean up the workspace that was created during execution of the build.   The workspace is defined in our scripts that get executed during the build.
 
what this comes down to is I want to remove the contents of the directory (bParent.build.properties.environment('GIT_TREE')) except a specific child folder in that directory.
 
From bash I can do this by executing
 
 

find <bParent.build.properties.environment('GIT_TREE')> -mindepth 1 -type d ! -iname images -exec rm -rf {} \;

where <bParent.build.properties.environment('GIT_TREE')> is translated to my working path.

However when I have tried to even print my command at the end of my build execution I end up with an error.

What I have tried (along with some variations) at this point is:

shell(find ${bParent.build.properties.environment['GIT_TREE']} -mindepth 1 -type d ! -iname images )  - this fails with

Script1.groovy: 44: unexpected token: $ @ line 44, column 15.
     shell( find ${bParent.build.properties.environment['GIT_TREE']} -mindepth 1 -type d ! -iname images
 
 println (find bParent.build.properties.environment['GIT_TREE'] -mindepth 1 -type d ! -iname images).execute - this fails with
Script1.groovy: 42: unexpected token: bParent @ line 42, column 15.
   println (find bParent.build.properties.environment['GIT_TREE'] -mindepth 1 -type d ! -iname images)
 
a basic
  println bParent.build.properties.environment['GIT_TREE']  gives me the directory I want to clean up
 
 
I don't want to put this in a separate shell script and build job to keep our build graph clean and to not confuse our developers.    I want this to execute at the end of the current process.  Does anyone have any suggestions on how to handle this situation? 
  
 

Baptiste Mathus

unread,
Feb 25, 2015, 1:04:22 AM2/25/15
to jenkins...@googlegroups.com

Either try to use the workspace cleanup plugin and/or some groovy step to do that and retrieve that variable?
My 2 cents

--
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/a51f8bc3-d319-4ca6-b04e-2fea74d542b5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

John Mellor

unread,
Feb 25, 2015, 8:41:50 AM2/25/15
to jenkins...@googlegroups.com

Ø  Either try to use the workspace cleanup plugin and/or some groovy step to do that and retrieve that variable?

 

We use git, so ymmv.  Rather than cleaning up at the end of a build, I just leave it all there and check the “Wipe out repository & force clone” selection in the “Additional Behaviours” section of “Source Code Management”.  That will checkout a whole new workspace every time the build starts, which I believe will have the same effect as what you are attempting.

Katie Outram

unread,
Feb 25, 2015, 12:15:40 PM2/25/15
to jenkins...@googlegroups.com
So what I have done so far is  
 
cleanup=bParent.build.properties.environment('GIT_TREE')
  println "find ${cleanup} -maxdepth 1 -not -name images -type f -exec rm -f {} +".execute().text
 
However, the
  println "find ${cleanup} -maxdepth 1 -not -name images -type f -exec rm -f {} +".execute().text
does not execute within the build flow plugin that we are using.
 
I have done just a
  println "find ${cleanup} -maxdepth 1 -not -name images -type f -exec rm -f {} +"  - and this line is correct, and I can run this manually and it works
 
 
Does anyone have suggestions on how to make this work using the build flow plugin?

Katie Outram

unread,
Feb 27, 2015, 10:27:28 AM2/27/15
to jenkins...@googlegroups.com
The information below does work as long as the location can see the child directory that needs to be cleaned up.
Reply all
Reply to author
Forward
0 new messages