Archive the artifacts in Jenkins

Continuous IntegrationHudsonArchiveJenkinsArtifacts

Continuous Integration Problem Overview


Could someone please explain to me the idea of artifacts in the build process?

I have the workspace directory where I check out the code to compile and run my ant scripts etc. At the end, in my case, I get a jar file that's ready to install. Is that considered to be the artifact?

Where should I tell my build script to put the jar file? In the workspace directory? My jar file gets a unique filename depending on variables like BUILD_ID and such, how can I tell Jenkins which jar file to pick?

EDIT: Okay, so i tried doing something like this:

enter image description here

The path does not exist yet in my workspace, because the build script is supposed to create it, and of course, the .jar and .properties files are not there because they haven't been generated yet. Why does it give me an error then? Seems like I'm missing something.

Also, does Jenkins delete the artifacts after each build (not the archived artifacts, I know I can tell it to delete those)? Otherwise it will clog the hard drive pretty quickly.

Continuous Integration Solutions


Solution 1 - Continuous Integration

Your understanding is correct, an artifact in the Jenkins sense is the result of a build - the intended output of the build process.

A common convention is to put the result of a build into a build, target or bin directory.

The Jenkins archiver can use globs (target/*.jar) to easily pick up the right file even if you have a unique name per build.

Solution 2 - Continuous Integration

An artifact can be any result of your build process. The important thing is that it doesn't matter on which client it was built it will be tranfered from the workspace back to the master (server) and stored there with a link to the build. The advantage is that it is versionized this way, you only have to setup backup on your master and that all artifacts are accesible via the web interface even if all build clients are offline.

It is possible to define a regular expression as the artifact name. In my case I zipped all the files I wanted to store in one file with a constant name during the build.

Solution 3 - Continuous Integration

> Also, does Jenkins delete the artifacts after each build ? (not the archived artifacts, I know I can tell it to delete those)

No, Hudson/Jenkins does not, by itself, clear the workspace after a build. You might have actions in your build process that erase, overwrite, or move build artifacts from where you left them. There is an option in the job configuration, in Advanced Project Options (which must be expanded), called "Clean workspace before build" that will wipe the workspace at the beginning of a new build.

Solution 4 - Continuous Integration

In Jenkins 2.60.3 there is a way to delete build artifacts (not the archived artifacts) in order to save hard drive space on the build machine. In the General section, check "Discard old builds" with strategy "Log Rotation" and then go into its Advanced options. Two more options will appear related to keeping build artifacts for the job based on number of days or builds.

The settings that work for me are to enter 1 for "Max # of builds to keep with artifacts" and then to have a post-build action to archive the artifacts. This way, all artifacts from all builds will be archived, all information from builds will be saved, but only the last build will keep its own artifacts.

Discard old builds options

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionMichaelView Question on Stackoverflow
Solution 1 - Continuous IntegrationAnders LindahlView Answer on Stackoverflow
Solution 2 - Continuous IntegrationMatthias AlleweldtView Answer on Stackoverflow
Solution 3 - Continuous IntegrationCodex24View Answer on Stackoverflow
Solution 4 - Continuous IntegrationMattView Answer on Stackoverflow