Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jenkinsfile archive step: allow missing artifacts

Under the regular UI defined jobs I can select "Do not fail build if archiving returns nothing". How do I achieve the equivalent in pipeline code?

E.g. currently I have something along these lines:

archive 'screenshots/**', 'build/test/results/*.xml'

and it is OK if there are no screenshots since there would be none if all tests pass.

like image 731
Friedrich 'Fred' Clausen Avatar asked Feb 22 '17 06:02

Friedrich 'Fred' Clausen


People also ask

How do I archive artifacts in Jenkins?

Go to your client project and select configure. Create a post-build action and select 'archive artififacts' from the drop down menu. Add the type of files you want to archive (and eventually, copy and export).

How do I archive multiple artifacts in Jenkins pipeline?

You can use Ant-style pattern, e.g. target/*. jar to archive multiple artifacts. And it is possible to use a comma separated list of patterns if your files can't be matched with one pattern, e.g. target/*. jar, target/*.

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.

How do you save artifacts in Jenkins?

In Jenkins, an artifact is created in either Freestyle projects or Pipeline projects. In Freestyle, add the “Archive the artifacts” post-build step. In Pipeline, use the archiveArtifacts step.


1 Answers

Use the new archiveArtifacts command, like this:

archiveArtifacts artifacts: 'screenshots/**,build/test/results/*.xml', allowEmptyArchive: true

Find the complete documentation of this command at https://jenkins.io/doc/pipeline/steps/core/#archiveartifacts-archive-the-artifacts

like image 73
Jon S Avatar answered Sep 16 '22 22:09

Jon S