135

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.

Michael
  • 19,964
  • 33
  • 119
  • 171
  • 12
    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. :) – Anders Lindahl Apr 28 '11 at 16:28
  • 3
    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). – Huang F. Lei Feb 04 '12 at 08:11

4 Answers4

68

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.

Anders Lindahl
  • 38,350
  • 8
  • 81
  • 88
  • @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 ? – Michael Apr 28 '11 at 16:33
  • 7
    @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. – Anders Lindahl Apr 28 '11 at 16:44
  • @Michael You can add a 'clean' build step. E.g. with Maven - `sh 'mvn clean package'` – Snowcrash Feb 27 '17 at 11:43
  • @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? – user3240688 Mar 08 '18 at 15:23
  • @user3240688 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. – Anders Lindahl Mar 08 '18 at 21:33
11

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.

gsamaras
  • 66,800
  • 33
  • 152
  • 256
Matthias Alleweldt
  • 2,333
  • 15
  • 16
  • 3
    "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 ? – Chris Milburn Jun 18 '14 at 10:59
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.

Codex24
  • 304
  • 4
  • 14
1

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

Matt
  • 231
  • 3
  • 9