12

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?

tbop
  • 394
  • 1
  • 3
  • 13

4 Answers4

3

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

Juanmi Sosso
  • 156
  • 1
  • 12
1

What I've done in this cases is create a compressed file (tar or zip) of the directory I'm interested, and then artifact it instead artifact the whole directory. If your slave is running in linux you can do as follow:

tar -czvf name-of-archive.tar.gz /path/of/build/directory

Then artifact name-of-archive.tar.gz

1

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.

anil kumar
  • 774
  • 7
  • 7
-1

You can check the option "Flatten directories" on the plugin's settings

maxx-nomad
  • 11
  • 4