Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Archive artifacts in jenkins

I have issue with archiving folder path in jenkins. I want only to archive what is inside my projects debug folder. I use following to do that.

MyApp1/MyApp1/bin/Debug/*

When I use that it will archive what inside debug folder but keep the same folder structure (MyApp1/MyApp1/bin/Debug).
If I only need t archive the files inside debug (Debug/) folder what shoud I do.

Please advice me.

like image 905
New Developer Avatar asked Jun 26 '13 04:06

New Developer


People also ask

Where does Jenkins archive 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 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/*.

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.

How do I remove an artifact from Jenkins?

The artifacts for a build by default are located in: [JENKINS_HOME]/jobs/[job_name]/builds/[$BUILD_ID]/archive/ , go there and delete it.


2 Answers

A cleaner way might be to have a stage dedicated to producing artifacts, set up with the appropriate working directory:

    stage('Release') {
        steps {
            dir('MyApp1/MyApp1/bin/Debug') {
                archiveArtifacts artifacts: '**', fingerprint: true
            }
        }
    }
like image 94
Bruno Lalande Avatar answered Oct 21 '22 11:10

Bruno Lalande


I created a method to achieve this:

def archiveFilesWithoutPath(globPattern) {
    def files = findFiles(glob: globPattern)
    for (def i = 0; i < files.size(); i++) {
        def file = files[i]
        def parentFolder = new File(file.path).getParent()
        dir(parentFolder) {
            archiveArtifacts file.name
        }
    }
}

Is is used like this:

archiveFilesWithoutPath '**/build/libs/*.jar'

The only downside currently is that you need to allow

new java.io.File java.lang.String

and

method java.io.File getParent

In the script approval.

like image 28
Roemer Avatar answered Oct 21 '22 11:10

Roemer