Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can a Jenkins build access the archived artifacts from itself?

Tags:

jenkins

I'm using Jenkins and have the "Archive the Artifacts" step at the end of my builds to archive them into a zip file.

Instead of using this step, I'd like to use a script to push the artifacts to a remote server at the end of the build. The server I'm pushing to uses a REST API / HTTP PUT request in a script to upload files.

Note that I'm looking to access the artifact created in the same build. So if I'm on build #5, I want the artifacts from build #5, not build #4.

Is there any way to access this zip file with a script, in the same build that it was created in?

I need to upload this zip remotely and don't want to create another job to do so.

like image 928
DonBecker Avatar asked Jan 13 '12 15:01

DonBecker


People also ask

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.

What does Archive artifacts do in Jenkins?

Archive of the artifacts in Jenkins is a feature that allows us to store the output files after we build the project with Jenkins. For example, you have an application project that uses Apache Maven to build. Normally we will use the “mvn clean install” command to build the Apache Maven application.


3 Answers

You can install one of the "Publish Over..." plugins to upload your artifacts at the end of a build.

The goal of the Publish Over plugins is to provide a consistent set of features and behaviours when sending build artifacts ... somewhere.

See also the full list of "upload" plugins for other methods of publishing your artifacts.

like image 198
Christopher Orr Avatar answered Nov 03 '22 00:11

Christopher Orr


Like @Christopher said, you can use any of the Publish Over plugins on the Jenkins Plugins page to upload the artifact to any of the

If you want to access the archived zip file from within the build itself, you can use the following link to access it:

http://<server>/job/${JOB_NAME}/lastSuccessfulBuild/artifact/<artifact name w/folder>

For example:

  • server = myserver.com
  • job name = myproject
  • artifact = del/project.zip

Your URL would be:

http://myserver.com/job/myproject/lastSuccessfulBuild/artifact/del/project.zip

EDIT: Question was changed. In any case, this would work for accessing the artifact of the previous build in the current one.

like image 33
Sagar Avatar answered Nov 03 '22 01:11

Sagar


There is no way that I have found to access the "Archive the Artifacts" package of the build that generates it. This step always occurs last in the build. Accessing the URL prior to the build ending (during the build via script for example) results in a blank zip file. To get around this limitation, I'm making a second linked build job to grab the zip and run my script to deploy it.

like image 36
DonBecker Avatar answered Nov 03 '22 02:11

DonBecker