Archive artifacts in jenkins

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
            }
        }
    }

You cannot remove the 'prefix' of a path using just the archive artifacts setting. (Some of the upload extensions do support this - the Publish over FTP plugin for example)

If you really need this a simple solution is to add an extra build step that copies your Debug folder to the root of the project workspace.


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.