Jenkins - Add download link to file if build fails - jenkins

I'm a little new to Jenkins, and I can't seem to figure this out. I have access to a Jenkins server that uses slaves to perform build jobs.
If a build fails, it stores a generated zip archive in a persistent Workspace directory for further debugging. The zip file is generated by a python script that keeps track of only the last 3 failed builds to conserve memory (i.e. 3 failed builds will result in 3 archives in the folder, but a fourth failed build will delete the oldest archive before adding the new one).
What I'm trying to do is add a download link to a failed Jenkins Run to allow users to quickly download the zip file that was generated for that build. But I'm really confused as to how approach this!
So I guess the question is, how could I add a download link to a Jenkins Run page to a file generated during that Run if it fails?
Example usage scenario:
1. I build some code :)
2. It fails :(
3. I download the zip file (from the Run page) with the generated debug files and find the fix :)
4. Space doesn't get filled up as zip files are kept only for the last 3 builds!
Any help would be greatly appreciated! Thank you! I'm happy to provide more information if needed ^^ I am currently trying to use a system groovy script to do this, but perhaps artifacts would be more appropriate? I really can't seem to find good documentation on this!

There are built in methods in Jenkins to allow this workflow:
you can archive any artifact (in that case the zip) as post build step
data retention strategy can be configured in the job via Discard old builds (Advanced).
in order to send out customized mails on build failure with embedded download link you should review Email Ext Plugin; it allows you to configure individual texts for e.g. build failures where you could add the link to downloading the artifact.

Related

How send folder as attachments in Jenkins Job Email Notification

I have A Jenkins Job with Workspace C:\hello_world\test_output*
in the test output folder, 2 things are one folder and one HTML file I want to send test output folder as a zip file as attachments on Jenkin jobs but I can't able to do it, please help
Think of it as two steps: 1) zipping the files; and 2) sending the attachment.
I've done this by installing 7zip, then running the command:
"C:\Program Files\7-Zip\7z.exe" a -r C:\hellow_world\test_output.zip C:\job\test_output\* - mem=AES256
With the https://plugins.jenkins.io/email-ext plugin installed, there's a lot of flexibility, including the ability to send attachments.
Bear in mind that some mail hosts example GMAIL have started blocking things like executables, even when found within zip files. If you've got users on such a host, you might run into trouble through no fault of your own.
Apart from that, depending on the OS that Jenkins is running on, you could add a post-build Execute shell or Execute Windows Batch command step that calls the zip tool of your choice, and send an e-mail with attachments using the email-ext plugin for example

Can JENKINS create build by excluding particular files?

I am actually trying to ignore a particular file to be included in the build. Actually it is a thumb.db file which is automatically created whenever images are encountered in a folder. My solution contains the image folder. So basically, whenever the build is triggered from JENKINS, it will create the thumb.db file.
Is there any way, I can ignore the Thumb.db file from getting created via JENKINS?
I can switch off the thumb.db file from creation by switching it off from my windows, but I have to do it every time a build is created from JENKINS. So I want to ignore the thumb.db file from creation.
Below is the Job creation flow in my JENKINS from my current project:
SCM
I have used the Team Foundation Server Plugin and have mentioned my SERVER URL and PROJECT PATH
POST BUILD steps simply create the build to the staging location(folder Location)
Any help is appreciated.
Thanks,
AFAIK, on windows you can turn it off or on for the whole system and not for particular folders.
So you have to choose. On or off.
If you still want to keep it on, you'l have to handle this in your Jenkins build scripts. Remove any thumbs.db files after build is done.
If your output is an archive, make sure to exclude thumbs.db from it. All archives support an exclude flag.
I hope this helps.

Creating artifacts in jenkins

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.

Accessing logs of TFS builds via script or folders

We'd like to build a script that checks for certain output in the build log, analyzes it and sends results to the person in charge.
What would be the best way to access the logs?
Is there any property that points us to the location of the log file so we could perform this step in the post-build step?
Can we copy the log via the build definition or manually in the post-build step to some folder?
Right now we're stuck getting access to the log file of completed builds at all -
except manually via the web interface or in VS..
If you are running a drop folder as part of your build the log files will be dropped their, the path will always be.
DropLocation\BuildName\Build\logs
So you can work out where the log file will be created and use the DropLocation property to identify the path (Microsoft.TeamFoundation.Build.Activities.Extensions.WellKnownEnvironmentVariables.DropLocation in TFS2013)

Can a Jenkins build access the archived artifacts from itself?

I'm using Jenkins and have the "Archive the Artifacts" step at the end of my builds to archive them into a zip file.
Instead of using this step, I'd like to use a script to push the artifacts to a remote server at the end of the build. The server I'm pushing to uses a REST API / HTTP PUT request in a script to upload files.
Note that I'm looking to access the artifact created in the same build. So if I'm on build #5, I want the artifacts from build #5, not build #4.
Is there any way to access this zip file with a script, in the same build that it was created in?
I need to upload this zip remotely and don't want to create another job to do so.
You can install one of the "Publish Over..." plugins to upload your artifacts at the end of a build.
The goal of the Publish Over plugins is to provide a consistent set of
features and behaviours when sending build artifacts ... somewhere.
See also the full list of "upload" plugins for other methods of publishing your artifacts.
Like #Christopher said, you can use any of the Publish Over plugins on the Jenkins Plugins page to upload the artifact to any of the
If you want to access the archived zip file from within the build itself, you can use the following link to access it:
http://<server>/job/${JOB_NAME}/lastSuccessfulBuild/artifact/<artifact name w/folder>
For example:
server = myserver.com
job name = myproject
artifact = del/project.zip
Your URL would be:
http://myserver.com/job/myproject/lastSuccessfulBuild/artifact/del/project.zip
EDIT: Question was changed. In any case, this would work for accessing the artifact of the previous build in the current one.
There is no way that I have found to access the "Archive the Artifacts" package of the build that generates it. This step always occurs last in the build. Accessing the URL prior to the build ending (during the build via script for example) results in a blank zip file. To get around this limitation, I'm making a second linked build job to grab the zip and run my script to deploy it.

Resources