Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to customize file name of Jenkins archive artifact plugin post build action?

Jenkins archive artifact plugin compress files into "archive.zip" file. It has always the same file name. Even more, Jenkins doesn't archive actually(there is no any "archive.zip" files in "builds" directories). Jenkins just map url

https://www.my-jenkins-server.com/jenkins/job/$job_name/$job_number/artifact/*zip*/archive.zip

and always return everything in job directory, those matches to pattern configured in post build action archive artifact plugin.

Problem is, that job itself generates ZIP archive, so I need to publish this archive under original name. It is important, since archive's name clarify owner of job, data inside, parameters used to run job. Let's say users ran job 10 times using different parameters and don't wait each job to finish before to run next. Later user will start download results and get

archive.zip
archive(1).zip
archive(2).zip
...
archive(10).zip

Now he needs to extract archives from those downloaded archives, to get 10 another archives with qualified names. Then delete those downloaded archive. After that, identify by qualified archive name those he needs actually and delete rest of then. Easy to make mistake here, delete or miss archive file.

Solutions for me are:

  1. Publish generated by job archive under it's original name.

  2. Generate my files and form file name of archive under with it should be served, skip zipping inside of job. Final step, pass this file name as parameter into archive artifact plugin post build action, so Jenkins will serve archive under special name configured by job itself.

like image 777
simar Avatar asked Mar 16 '15 09:03

simar


People also ask

How do I configure archive artifacts in Jenkins?

Go to your client project and select configure. Create a post-build action and select 'archive artififacts' from the drop down menu. Add the type of files you want to archive (and eventually, copy and export).

How do you archive artifacts in Jenkins pipeline?

Normally, Jenkins keeps artifacts for a build as long as a build log itself is kept, but if you don't need old artifacts and would rather save disk space, you can do so. Note that the Maven job type automatically archives any produced Maven artifacts. Any artifacts configured here will be archived on top of that.

Where does Jenkins store archived artifacts?

By default, Jenkins archives artifacts generated by the build. These artifacts are stored in the JENKINS_HOME directory with all other elements such as job configuration files.


2 Answers

The name of the zip file is determined from the directory that contains the artifacts (see Jenkins source).

  • Internally, the top-most artifact directory has the name archive, that's why you will always see archive.zip.

  • Conversely, this means that you can get a custom zip file xyz.zip by putting the artifacts in a (sub-)directory xyz.

There are no other options to change the name.

like image 71
Alex O Avatar answered Sep 18 '22 05:09

Alex O


You can run any post-build script (shell/batch/powershell) after the archive step, and rename archive.zip to archive_${BUILD_NUMBER}.zip so that you can easily track of the archive by the last successful build number of the job. But to do this, first you need to clean the workspace to keep a track of the archive files based on the build number.

like image 43
Surendra Deshpande Avatar answered Sep 21 '22 05:09

Surendra Deshpande