Jenkins sending attachments with email plugin - jenkins

I'm trying to attach a file when a test fails in Jenkins.
I'm using the email extension plugin as a means of trying to achieve this but I'm stumped by the syntax.
If I simply put "index.php" (without quotation marks) in the attachment field it will send out the attachment correctly.
If I try and go further into the workspace e.g."myfolder/myfile.php" (without quotation marks) the email wont send. I've tried a number of variants, using wildcards and trying to target files specifically but with no luck.
I have of course looked here http://ant.apache.org/manual/Types/fileset.html but nothing seems to work.

Try **/myfile.php
This will look for myfile.php regardless of the directory structure

Related

How to start a build via a phrase in Jenkins Pipelines

I am switching from the github pull request builder plugin (for security reasons) and am trying to get the same functionality from Pipelines (using different plugin). I think I have just about everything, however I can't seem to find a way to re-trigger a build simply by a trigger phrase like in github pull request builder plugin. Is that possible via pipelines?
By trigger phrase, I mean that a user can make a comment on the PR saying "Jenkins re-test" and it will kick off the build again.
You can put a condition at the top of the build script to check for the message. You can access the changesets using currentBuild.ChangeSets. The last changeset is at the end of the array. Then you need to access the last element of that changeset. Finally you can access the message via message property. You can then search for your keyword.
I am doing the opposite (not triggering the build with a phrase) but never tried for pullrequests though.
Another idea is to use the "ignore builds with specific message" property and setting this message to be a regex with look ahead that accepts everything except the keyword. I don't really recall the syntax though :/

Sending robot framework log file as email content via Jenkins is not getting displayed

I have created a Jenkins job to execute robot framework. The results[log.html and report.html] of the Jenkins are getting displayed properly.
Now I am using the email-ext plugin to send the log file as email content to the specified group of users, but the received email doesn't display the content and shows error as "Opening Robot Framework log failed" in the email.
I have set the email-ext plugin as follows:
I wish to send the robot results as email content, not as an attachment, I have tried various methods like Linux, shell scripting etc, but still, it doesn't work. How can the log.html email content can be sent to the email body?
You will not be able to just put the entire content of the robot log.html in an email because it contains javascript.
I've been looking into this the last few days as well and have come to see that using a groovy based template using the jenkins Email-ext plugin is the way to go. Googling for 'jenkins robot framework email template' shows a few hits and one that I'm planning to try and then modify to my liking was this one:
https://github.com/vladwa/robot-email-template
From this I found that we don't have access to all of the test info built in, so I wrote up some modifications to load the robot output.xml as an artifact to then be able to inject any data in that file into the html email report. Here's the gist of that:
https://gist.github.com/harbdog/070f0be66ebae343d6d11e57a6c6fc08
Here's what it looks like for example:
You have to configure publish robot framework test result <post build> and then use {ROBOT_REPORTLINK} in email content section

create hyperlink to file server in pipeline jobs console

I want to print a hyperlink to a file I created while running a pipeline job. This simple .txt file should be opened after hitting the link. I found this wiki entry but there is no example implementation. Is there a way to perform this? I dont know how to trigger the 'explorer' call. (this is for windows use only)
I used : '<file://link/to/folder/>' and its working ;)

I'm getting JellyException: Could not parse Jelly script : null

I'm trying to configure some features in Jenkins for our project.
In the process of configuring Editable Email Notification, I have created a new jelly script file in $JENKINS_HOME/email-templates folder as shown here
and accessing it in Jenkins config like this
When I build the job, with these setting, I'm getting email with the content
"JellyException: Could not parse Jelly script : null"
Thanks in advance!!
I faced a similar issue after I updated my Jenkins installation. I used the "Email Template Testing" feature to verify my script, but kept getting
JellyException: Could not parse Jelly script : null
In my case the issue was caused because of the use of jelly:util library in my jelly script. The script used u:loadText and u:file tags.
It seems that newer version of Jenkins do not include the jelly:util library, required for using the util tags. I resolved the issue by manually placing the commons-jelly-tags-util-1.1.1.jar file in the \war\WEB-INF\lib directory of Jenkins and restarting it.
There are two issues that are usually encountered when working with email templates (and there is another issue#2.5 will i'll explain as well :) )
I faced this issue when I copied/created new scripts from a different user rather than the one that Jenkins uses to run as. So in this case if 'ubuntu' is not the user that runs Jenkins as well, consider chowning the file and group to the user/group of jenkins user.
There were times when my jelly actually had an error which could not let it be parsed. I came to know about it from using the 'Email Template Testing' option available in the job options, which resulted in the same error
Now for the 2.5 issue
2.5. Please be cognizant of the fact that jelly templates have a different placeholder than the template-email-templates.
The '.template' files are loaded using ${SCRIPT} and '.jelly' Jelly scripts are loaded using ${JELLY_SCRIPT} tags, if you use JELLY_SCRIPT tag to load a template, you might end up with the same error as well.
This point is naive but it's worth listing it here so that anyone with this issue has all the checkpoints required to fix this issue.

How to upload a generic file into a Jenkins job?

I am trying to find a way to prompt the user to select and upload a generic file from a local machine to a Jenkins job prior to build. The input file that user is going to upload is not necessarily a text or a property file.
I am specifically trying to get the user to "select" their desired file - browse to their file ; the user should not pass the file's path.
Thanks
Use the File Parameter:
File parameter allows a build to accept a file, to be submitted by the user when scheduling a new build. The file will be placed inside the workspace at the known location after the check-out/update is done, so that your build scripts can use this file.
If you need to verify the file has a certain extension, you would have to do that with a script as part of your job, and fail the job is extension/content-type does not match what you need.
This is kind of annoying to handle when you don't know what the file name will be or need to change its name before it reaches its destination. You kind of need to perform a hack. This is how I do it:
Use the "File parameter" parameter to upload your file
Use the OS-specific script to rename the file from whatever you named your File Parameter to whatever you want it to be, e.g., if my File Parameter had the File location value of file_name instead of an actual relative file-path, I'd then do something like this for say, Windows inside a Build-Step for "Execute Windows Batch Command":
move .\file_name .\%file_name%
And then just use ArtifactDeployer to copy everything there to your desired location.
ps: this won't remove digital signatures, so the move-operation should be considered mostly safe.
The use of the Jenkins File Parameter will not work for Jenkins pipelines. It's ridiculous that they don't disable that kind of build parameter for pipelines. It's even more ridiculous that they don't at the very least, identify this SEVERE limitation in the help documentation for that parameter.
It would have saved me a couple hours trying to figure out why it would not work in my pipeline.
Refer to this feature request for more details: https://issues.jenkins-ci.org/browse/JENKINS-27413

Resources