Mona
Mona

Reputation: 352

Deleting Workspace Post Maven Execution in LInux Machine

Our frame work is developed in a way that the whole project will be copied (from Perforce) to Linux machine (remote VM machine) and there a Maven command is executed to run test cases. Everything is driven through Jenkins.

After executing the test cases, I delete the workspace using an Execute shell post Maven build step. As expected it's deleting the workspace. My problem after deleting the workspace: not sure why again it's parsing POM? This causes the job to fail though test cases executed successfully.

This is how I configured to delete the workspace:

enter image description here

Upon running job, it's deleting the workspace as expected but parsing POM post deletion. Obviously POM will not be there as it deleted the workspace.

INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1:11:26.091s
[INFO] Finished at: Mon Nov 02 22:50:42 PST 2015
[INFO] Final Memory: 133M/489M
[INFO] ------------------------------------------------------------------------
[JENKINS] Archiving disabled
[JENKINS] Archiving disabled
[JENKINS] Archiving disabled
[JENKINS] Archiving disabled
[JENKINS] Archiving disabled
[JENKINS] Archiving disabled
[JENKINS] Archiving disabled
[JENKINS] Archiving disabled
[JENKINS] Archiving disabled
[JENKINS] Archiving disabled
[JENKINS] Archiving disabled
Waiting for Jenkins to finish collecting data
channel stopped
[testjob] $ /bin/sh -xe /tmp/hudson464395510348605766.sh
+ echo testjob
testjob
+ delworkspace=/opt/hudson/workspace/testjob
+ rm -rf /opt/hudson/workspace/testjob
ERROR: Failed to parse POMs
java.io.IOException: java.io.FileNotFoundException: /opt/hudson/workspace/testjob/pom.xml (No such file or directory)
    at hudson.remoting.FastPipedInputStream.read(FastPipedInputStream.java:169)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
Notifying upstream projects of job completion
Finished: FAILURE 

Do I miss anything in configuration? I did all homework, but no luck.

Upvotes: 1

Views: 1062

Answers (2)

Sajib Khan
Sajib Khan

Reputation: 24166

You can do it with Parameterized Trigger Plugin easily.

  • What you should do: create a new job (say, named cleanWS), when build is completed, it will trigger cleanWS & delete your job's workspace instantly.

  • Go testjob configure -> select Execute shell from Build section -> copy and paste echo delworkspace=/opt/hudson/workspace/$JOB_NAME >> file.properties.

  • In Post-build Actions section:

      Add post-build action -> Trigger parameterized build on the projects
      Projects to build -> <job name e.g. cleanWS>  
      Trigger when build is -> Complete (always trigger)
      Add Parameters -> Parameters from properties file
        Use properties from file -> file.properties
    
  • press save.

  • Then go your cleanWS configure -> select Execute shell from Build section -> copy and paste rm -rf $delworkspace.

N.B. With this cleanWS job you can delete your all job's workspace.

Upvotes: 1

Gerold Broser
Gerold Broser

Reputation: 14762

I'd use the Workspace Cleanup Plugin:

This plugin deletes the workspace before the build or when a build is finished and artifacts saved.

instead of removing the workspace via an own script.

Upvotes: 0

Related Questions