Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jenkins delete files from Workspace

I have jenkin's job, which copy tar file from linux user folder and then copy binary file (compiled) from another job and make new tar file. Then jenkins user can copy that new tar file from jenkin's workspace. It doesn't build anything or take files from SCM. Then after a while, suddenly tar file has been deleted from workspace, I have to run job again. How I can prevent that?

like image 323
user1869474 Avatar asked Nov 20 '25 13:11

user1869474


1 Answers

You really shouldn't rely on your workspace existing after a job has completed, as the workspace can be overwritten by another build starting, or when someone deletes a build, by a slave going offline, etc...

Since you want to save the file for later use, you should use the "Archive the artifacts" option in your job's post-build configuration. If you enter **/*.tar, for example, Jenkins would save all TAR files at the end of the build.

Then you can use Jenkins' permalinks to access the artifacts, e.g.:
http://JENKINS/job/JOB_NAME/lastSuccessfulBuild/artifact/bin/my-app.tar

As the URL suggests, this would give you the file from the last successful build.


As a sidenote, if you then want to copy archived files to another build, the best way to do this is with the Copy Artifact plugin.

That way Jenkins handles the file copying for you, even across multiple Jenkins slaves, and you don't have to do anything nasty like hard-coding paths to other Jenkins workspaces.

like image 191
Christopher Orr Avatar answered Nov 25 '25 00:11

Christopher Orr



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!