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.
Related
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.
Unfortunately imgur is blocked here at my workplace, so instead of screenshots of my build definition I will have to explain my build definition settings to the best of my ability.
I have two build steps, the first is a maven build step that runs the "package" goal. Under the code coverage section of the maven settings I have the CodeCoverage Tool set as "Cobertura", which is what we use on our local boxes when maven building.
My second build step is "Publish Code Coverage Results". I am not sure exactly what to put for my summary file in the settings of this build step. I think that the problem is that the build agent takes the cobertura folder off of the build machine and puts it somewhere else not on the build machine. This is the log entry for what it is doing:
Uploaded artifact 'C:\TFS_BUILD_AGENTS\agent-1\_work\3\s\target\site\cobertura' to container folder 'Code Coverage Report_35241' of build 35241.
So I either need the Summary File location for wherever it is uploading to, or I need to have it not upload the folder like it is currently doing.
This is what I have as the summary file right now, which does not work:
Code Coverage Report_$(Build.BuildId)\coverage.xml
You could check in this file to TFS and map it down to the build agent server. Then you could some build variables(like $(Build.SourcesDirectory) which represents 'C:\TFS_BUILD_AGENTS\agent-1_work\3\s') to get the file.
So you need to put C:\TFS_BUILD_AGENTS\agent-1\_work\3\...\***.xml. Make sure the file is located at the path your specified.
If the file you want to upload is generated after the step1, please check which path is locates and point it in the Summary file blanket.
I have been tasked with looking into using Jenkins as a build server. So far I have managed to pull a project from git, restore the Nuget packages, build the project and run the unit tests. However I am struggling to find out how to generate the artifact.
The way the business would like to have the build server generate a zip file to a directory on the build server or a remote server for the systems team then to pick up and deploy to the relevant location. E.g. given a windows service project the built bin directory would be zipped up and put in the relevant artifact directory.
I thought that in order to do this I add an archive the artifacts post-build action. However I am getting the below error:
‘Watchdog.WinService.Monitor/bin/Release/*.zip’ doesn’t match anything:
‘Watchdog.WinService.Monitor’ exists but not
‘Watchdog.WinService.Monitor/bin/Release/*.zip’
If I look in the workspace for this project I can browse to the bin directory and see all the files so I unsure what I have done wrong.
Can someone please let me know if what I am trying to accomplish is possible, and also if our approach to using Jenkins is correct?
The problem is that you try to create the artifact using the archive artifatcs step.
But the step is to collect artifacts and show them on the job page.
That means you need to create the artifact first e.g. using a shell or batch script.
You can combine this with the Flexible Publish Plugin.
When you select this as post build step you can create a conditional action that runs the artifact archive task and as condition executes the script that creates the zip file.
So if that fails the task won't be executed. Also it may causes your job to 'fail' but that may not be the case in your job.
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.
When an ANT build step fails in my build I'd like to archive the logs in order to determine the problem. The relevant logs, however, are not located in the workspace, so I have to use a full path to them.
The standard artifact archiving feature does not work well with full paths, so first I have to copy the logs into the workspace within some build step so that I can later archive them. I do not want to incorporate the copying code into the original ANT script (it does not really belong there). On the other hand, since the build step fails the build I can't execute the code that copies the artifacts into the workspace as a separate build step as it is never reached.
I am considering using ANT -keep-going option, but how will I then fail the build?
Any other ideas (artifact plugins that handle full paths gracefully, for example)?
Update: I've worked around the problem by creating a symbolic link in the workspace to the directory that contains the files to be archived. Kludgy, but effective.
I would recommend using Flexible Publish plugin in conjunction with the Conditional Build Step plugin.
The Flexible Publish plugin allows you to schedule build steps AFTER the build steps have normally run. This allows you to catch both successful and failed builds and execute something - say a script that copies the files from OUTSIDE the workspace to INSIDE the workspace. The Conditional BuildSet plugin allows conditionalizing the steps so that they only run when the build fails. Using these two plugins, you can copy the files into the workspace upon failure, then archive them with the usual Jenkins mechanisms.