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

tbop picture tbop · Jan 24, 2017 · Viewed 14.3k times · Source

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?

Answer

Juanmi Sosso picture Juanmi Sosso · Feb 7, 2020

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