My build job produces various artifacts, they are based on parameters but not directly computable from them. The artifacts are undetermined until the build steps complete.
Upon build steps completion, the newly created artifacts' file names are located in the designated file (known in advance)
I want to archive the artifacts by specifying their file names in that file. How can I do it?
P.S. From what I know, the "Archive the artifacts" step specs are similar to includes attribute of Ant fileset. I need something like includesfile.
You can read the file with the readFile step, and convert it to the format expected by archiveArtifacts (comma-separated String of items). E.g.:
String artifacts = readFile(file: 'artifacts.txt').split('\n').join(',')
archiveArtifacts artifacts
I was able to workaround the issue:
Add post-build script step (before archiving artifacts). In it: iterate over file names in the file, copy each to the designated (empty) folder
Configure the Archive artifacts step to take all files from that designated folder.
Related
I would like to get a zip file with artifacts.
The archiveArtifacts directive in Jenkinsfile will save each artifact,
but when you download it you will get a zip files with original paths in it.
Is it possible to avoid original paths with a directive or am I obliged to
run a script that callects all artifacts in one single folder in the workspace and zip the folder then?
I need to archive any .png screenshots of the latest katalon test run in Jenkins as a post-build step of the same test run.
Using the "archive the artifacts" post-build action in Jenkins, I currently have the file path set to Reports/**/[test run name]/**/*.png where Reports is in the workspace directory. However this will just pull every .png file from the current and all previous test runs stored there, of which are kept stored in the workspace for a week before being cleaned out.
I've tried using the "Exclude" field but haven't been able to figure out a way to exclude older files with only being able to use a file path with wildcards.
Is there a way in Jenkins, using archive the artifacts or something else, to archive just the .png files generated by the same job without deleting all previously generated .png files?
From our experience, it's better to keep the artifacts archived with the job and not rely on files residing in the workspace together with a separate job to clean them. You can tell Jenkins to discard old builds (and artifacts) with something like this:
pipeline {
options {
buildDiscarder(logRotator(daysToKeepStr: '7', artifactDaysToKeepStr: '7'))
}
}
And any jobs (and their artifacts) will be cleaned after 7 days.
If you go with that path, you can safely remove any png files after archiving them as artifacts, and you won't need to find out which are new and which are old.
Alternatively, you can order your png-producing step to name the files starting with the job number (available as env.BUILD_NUMBER) and only archive the files starting with this number.
Finally, you can run find command with -name '*png' and -mtime predicate to produce the list of recently modified png files, and use that as an input to the archive step.
I'm working on a basic Jenkins pipeline. The build and testing are successful but I'm looking at how to archive the build. For context, this is a simple Rust webserver.
Under the pipeline steps documentation in the Basic Steps plugin, it has the archive function. But it says:
Archives build output artifacts for later use. As of Jenkins 2.x, you may use the more configurable archiveArtifacts.
I cannot find any documentation on archiveArtifacts. There are some examples, but I would like to look at the documentation for it, what parameters it accepts, i.e. what makes it more configurable than archive.
My question: is there a place where this documentation is best found? jenkins.io is incomplete and wiki.jenkins.io is missing this command.
I suggest archiveArtifacts: Archive the artifacts from the Pipeline Steps Reference.
Archives the build artifacts (for example, distribution zip files or
jar files) so that they can be downloaded later. Archived files will
be accessible from the Jenkins webpage. Normally, Jenkins keeps
artifacts for a build as long as a build log itself is kept, but if
you don't need old artifacts and would rather save disk space, you can
do so.
Note that the Maven job type automatically archives any produced Maven
artifacts. Any artifacts configured here will be archived on top of
that. Automatic artifact archiving can be disabled under the advanced
Maven options.
artifacts
You can use wildcards like 'module/dist/**/*.zip'. See the includes attribute of Ant fileset for the exact format. The base directory is the workspace. You can only archive files that are located in your workspace.
Type: String
allowEmptyArchive (optional)
Normally, a build fails if archiving returns zero artifacts. This option allows the archiving process to return nothing without failing the build. Instead, the build will simply throw a warning.
Type: boolean
excludes (optional)
Optionally specify the 'excludes' pattern, such as "foo/bar/**/*". A file that matches this mask will not be archived even if it matches the mask specified in 'files to archive' section.
Type: String
I am new to jenkins and I have tried downloading a zip archive of this workspace in jenkins, but I only get a part of it. Source folders like tensorflow or tools are not present inside the archive. Is this normal ?
If so, how do I get all of them inside a zip file ?
Use Archive Artifact plugin, to add your workspace into archive folder which will make it easily down-loadable.
But be aware that, an artifact in the Jenkins sense is the result of a build - the intended output of the build process.
A common convention is to put the result of a build into a build, target or bin directory.
The Jenkins archiver can use globs (target/*.jar) to easily pick up the right file even if you have a unique name per build.
putting a complete workspace into it will take lot of time.
Jenkins archive artifact plugin compress files into "archive.zip" file. It has always the same file name. Even more, Jenkins doesn't archive actually(there is no any "archive.zip" files in "builds" directories). Jenkins just map url
https://www.my-jenkins-server.com/jenkins/job/$job_name/$job_number/artifact/*zip*/archive.zip
and always return everything in job directory, those matches to pattern configured in post build action archive artifact plugin.
Problem is, that job itself generates ZIP archive, so I need to publish this archive under original name. It is important, since archive's name clarify owner of job, data inside, parameters used to run job. Let's say users ran job 10 times using different parameters and don't wait each job to finish before to run next. Later user will start download results and get
archive.zip
archive(1).zip
archive(2).zip
...
archive(10).zip
Now he needs to extract archives from those downloaded archives, to get 10 another archives with qualified names. Then delete those downloaded archive. After that, identify by qualified archive name those he needs actually and delete rest of then. Easy to make mistake here, delete or miss archive file.
Solutions for me are:
Publish generated by job archive under it's original name.
Generate my files and form file name of archive under with it should be served, skip zipping inside of job. Final step, pass this file name as parameter into archive artifact plugin post build action, so Jenkins will serve archive under special name configured by job itself.
The name of the zip file is determined from the directory that contains the artifacts (see Jenkins source).
Internally, the top-most artifact directory has the name archive, that's why you will always see archive.zip.
Conversely, this means that you can get a custom zip file xyz.zip by putting the artifacts in a (sub-)directory xyz.
There are no other options to change the name.
You can run any post-build script (shell/batch/powershell) after the archive step, and rename archive.zip to archive_${BUILD_NUMBER}.zip so that you can easily track of the archive by the last successful build number of the job. But to do this, first you need to clean the workspace to keep a track of the archive files based on the build number.