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.
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.
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/*.
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.
The artifacts for a build by default are located in: [JENKINS_HOME]/jobs/[job_name]/builds/[$BUILD_ID]/archive/ , go there and delete it.
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
}
}
}
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With