Archive the artifacts in Jenkins
Asked Answered
A

4

137

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.

Arabinose answered 28/4, 2011 at 15:59 Comment(2)
The error you're getting is most likely not a problem - if the build process is successful, it should be created. Save and try this out, having a few broken builds while setting up the pipeline is perfectly normal. :)Extravagancy
Don't be scared by the warning, if a artifact is generated after build, it will be archived by your config(although there is a warning in config page).Remissible
E
70

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.

Extravagancy answered 28/4, 2011 at 16:11 Comment(5)
@Andres thanks, also, does jenkins delete the artifacts after each build (not the archived artifacts, i know i can tell it to delelte those)? or am i responsible to do it myslef ?Arabinose
@michael: You have to clean the workspace yourself, it's good practice to clear at least the target directory before every build to make sure you don't end up with the results of an earlier build.Extravagancy
@Arabinose You can add a 'clean' build step. E.g. with Maven - sh 'mvn clean package'Muscovado
@AndersLindahl - "common convention is to put the result of a build into a build, target or bin directory." You're referring to a bin directory that's shared by all projects? How do I do that? Is it a Post-build action?Slumberland
@Slumberland No, I'm referring to per-project target folders. If you want artifacts from several jobs into a single shared folder, you will have to publish the artifacts using for example one of the "Publish over $PROTOCOL" plugins.Extravagancy
M
12

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.

Milli answered 28/4, 2011 at 16:14 Comment(1)
"It is possible to define a regular expression as the artifact name. In my case I zipped all the files" Could you explain this ? it sounds exactly what I want ?Alfonso
W
7

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.

Waterage answered 9/1, 2015 at 17:6 Comment(0)
C
2

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

Concrescence answered 28/11, 2017 at 17:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.