76
votes

Is there a way to save/archive multiple artifacts from the same build?

Jenkins only allows a single 'Archive the Artifacts' post build step, and grey's out the option after it has been used once.

Maybe the ArtifactsArchiver's allows multiple patterns?

6
FYI This is not a limitation in Jenkinsfile / pipeline builds.simon.watts

6 Answers

101
votes

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/*.war.

The ? button next to the input field reveals this info.

36
votes

You can comma separate the paths, like this:

XXX.UnitTests\bin\Release\**.* , XXX.WriteAPI.Service/bin/Release/**.*

Then you get two separate artifacts.

See http://ant.apache.org/manual/Types/fileset.html for details of the Ant Pattern syntax.

11
votes

If you want to save two different types of files like zip files and html files, then you can use

*.html,*.zip

It will help you to archive all zip files and html files in that directory.

5
votes

No, jenkins does not provide only one artifact to save. You can use wild card pattern to same any number of artifacts, For example All Jars - **/*.jar All War - **/*.war and so on.

**/ means Any directory.

0
votes

All the answers on here show how to combine multiple file patterns into 1 artifact which is not what the OP asked for.

An example of what was asked for is to have something like a Single Page Web app build that has environment specific settings compiled into the JavaScript for QA, Staging and Production.

As you would want to deploy the same build to multiple environments, you would need 3 builds, each with it's own environment settings in it. When you deploy the archive, you would not want to deploy the contents of all 3 to each environment and extract just the content for that one environment, because it is expensive to copy 66% more than is needed each time and could be error prone.

So, it is reasonable to generate 2 or more builds into their own artifacts and deploy 1 of those artifacts, depending on the target environment.

Jenkins should support multiple artifacts, not just making 1 artifact bigger.

0
votes

Copying @Steven the Easily Amused's comment on one of the bottom-ranked answers for visibility. You can just run it twice:

Notice that the step names are plural. One can run archiveArtifacts - the pipeline step - as often as desired though it's more efficient to run it once with Ant style patterns. When invoked archiveArtifacts transports the selected file(s) back to the master where they are stored. Similarly one can run copyArtifacts multiple times to select all of or a portion of the archived Artifacts.