Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to archive the content of a folder recursively as artifacts on Jenkins?

My jenkins job creates a temporary subfolder, say "mydir", within the workspace that I then want to archive using the postbuild step "Archive artifacts".

I'm using the following command:

mydir/**/*

It works well but the archive will always contains mydir as the root of the artifacts whereas I would like to have the contents of this folder only.

How to do this?

like image 909
tbop Avatar asked Jan 24 '17 22:01

tbop


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 I archive a workspace in Jenkins?

You could simply archive the complete workspace at the end of a build. It would then get deleted when the job is deleted. To do this: Add post-build action -> "Archive the artifacts"


2 Answers

To archive your entire folder in jenkins.

In your case let us say. If you want to archive complete "mydir" folder

**/my_dir/**

That is one way. If you have other folders with the same name. Then you can provide proper parent directory as well.

like image 154
anil kumar Avatar answered Sep 21 '22 20:09

anil kumar


You can use dir() to archive the artifact from inside the desired directory:

    stage('Archive') {
        steps {
            dir('mydir') {
                archiveArtifacts artifacts: '**'
            }
        }
    }

https://jenkins.io/doc/pipeline/steps/workflow-basic-steps/#dir-change-current-directory

like image 40
Juanmi Sosso Avatar answered Sep 24 '22 20:09

Juanmi Sosso