38

I'm working on a basic Jenkins pipeline. The build and testing are successful but I'm looking at how to archive the build. For context, this is a simple Rust webserver.

Under the pipeline steps documentation in the Basic Steps plugin, it has the archive function. But it says:

Archives build output artifacts for later use. As of Jenkins 2.x, you may use the more configurable archiveArtifacts.

I cannot find any documentation on archiveArtifacts. There are some examples, but I would like to look at the documentation for it, what parameters it accepts, i.e. what makes it more configurable than archive.

My question: is there a place where this documentation is best found? jenkins.io is incomplete and wiki.jenkins.io is missing this command.

pmbotter
  • 493
  • 1
  • 6
  • 7
  • I can't close it, but I found what I needed. The documentation is built into Jenkins _Pipeline Syntax_ of your job. – pmbotter Dec 18 '17 at 23:31
  • The snippet generator (what you found) is generally the easiest and maps closest to what version of everything you are actually running. The documentation is generally poor and I always have to go directly to the source code. – mkobit Dec 19 '17 at 00:10
  • @pmbotter - In case the job is written in Jenkinsfile, I found these two short tutorials very useful (just to get started): https://jenkins.io/doc/pipeline/tour/tests-and-artifacts/ https://github.com/jenkinsci/pipeline-model-definition-plugin/wiki/Reporting-test-results-and-storing-artifacts – Guy Avraham Jun 23 '19 at 12:33

1 Answers1

45

I suggest archiveArtifacts: Archive the artifacts from the Pipeline Steps Reference.

Archives the build artifacts (for example, distribution zip files or jar files) so that they can be downloaded later. Archived files will be accessible from the Jenkins webpage. 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. Automatic artifact archiving can be disabled under the advanced Maven options.

  • artifacts
    You can use wildcards like 'module/dist/**/*.zip'. See the includes attribute of Ant fileset for the exact format. The base directory is the workspace. You can only archive files that are located in your workspace.
    • Type: String
  • allowEmptyArchive (optional)
    Normally, a build fails if archiving returns zero artifacts. This option allows the archiving process to return nothing without failing the build. Instead, the build will simply throw a warning.

    • Type: boolean
  • excludes (optional)
    Optionally specify the 'excludes' pattern, such as "foo/bar/**/*". A file that matches this mask will not be archived even if it matches the mask specified in 'files to archive' section.

    • Type: String
BlackBeard
  • 10,246
  • 7
  • 52
  • 62
sschmeck
  • 7,233
  • 4
  • 40
  • 67
  • 5
    The part that you where mentioned that "You can only archive files that are located in your workspace." saved me. – nisanarz Feb 25 '20 at 14:15
  • 7
    Knowing what parameters exist is great, but an example of the syntax might also help: `archiveArtifacts artifacts: './core', allowEmptyArchive: 'true'` – V-R Feb 17 '21 at 10:07
  • I don't understand the part "You can only archive files that are located in your workspace."?? Am I not always in my workspace? Is there more than one workspace? – Danijel Mar 07 '22 at 17:39
  • 1
    The `Jenkinsfile` is totally free to create files outside of the workspace and those are files you cannot archive with `archiveArtifacts`. – Bombe Apr 06 '22 at 12:47
  • 1
    You can always use a script to copy files into the workspace, and archive from there – John Kraemer Jun 29 '22 at 21:26
  • 1
    I just want to add: I couldn't find documentation on the last option 'onlyIfSuccessful' in https://www.jenkins.io/doc/pipeline/steps/core/. But the Snippet Generator (https://www.jenkins.io/doc/book/pipeline/getting-started/#snippet-generator) helped me out: opening the Pipeline Syntax page on Jenkins allowed me to build an example snippet for a pipeline in just a few clicks. It explained this option as "Archive artifacts only if build is successful". – Guillius Jun 29 '23 at 14:42