How to display a hyperlink in jenkins Blue Ocean UI? - jenkins

In Jenkins classic interface it is possible to create a link in the output console, but I can't see how I can make something clicable in the Blue Green interface.

You can get the solution here :
How to display a hyperlink in hudson/jenkins build output console
You can also use a workaround for that which is fairly customisable than the method mentioned above.
After finishing your build you can add functionality to your build to send a mail with the report link.
You can do it through the Jenkinsfile or using the job configuration as well.
The Jenkinsfile groovy script is as follows.
script {
emailext subject: ' REPORT-Version/'+ "${G_BRANCH}" + ' $DEFAULT_SUBJECT' ,
body: "Click the link below to show Mocha Testing Results for your current build :<br><br>BAE 4.5 Release Report" ,
attachLog: true,
replyTo: '$DEFAULT_REPLYTO',
to: '$DEFAULT_RECIPIENTS'
}
Through Job configuration you can go to Job --> Configure --> Post Build Actions --> Editable Email Notifications.

Well, it works almost out of the box. Blue Ocean automatically recognizes URL patterns and transform it in a clickable link. For example:
echo "CUCUMBER: ${BUILD_URL}cucumber-html-reports/overview-features.html"
Unfortunately it looks like it isn't possible to create a clickable arbitrary text.

Related

Jenkins: Passing user defined variables to Email-Ext plugin

I'm using the Email-Ext plugin to send a results email at the end of my build in the post build stage of a declarative pipeline. In the body of the email I'm trying to insert some environment variables and some user defined environment variables.
The built in variables show up fine, however any user defined variables I define are just empty in the body of the email or don't work in the attachmentPattern field either:
My environment variables:
pipeline {
agent any
environment {
buildFolder = "build_${BUILD_NUMBER}"
robotFolder = "build_${BUILD_NUMBER}/robotDemo"
serverName = "abc123"
robotResults = "${buildFolder}/*.txt"
}
The email-ext format I am using in my post{} build:
emailext attachLog: true, attachmentsPattern: 'build_${env.BUILD_NUMBER}/Robot_Results.txt', body: '<b>Job Name:</b> ${ENV, var="JOB_NAME"}<br><b>Build Number:</b> ${ENV, var="BUILD_NUMBER"}<br><br><b>Build URL:</b><br>${ENV, var="BUILD_URL"}<br><br><b>Log Files:<br><br><br><pre>${BUILD_LOG_EXCERPT, start="^====", end="^report.html"}</pre><pre>${ENV, var="serverName"}</pre>', mimeType: 'text/html', subject: 'ABS Results', to: 'richard.scott#sap.com'
For example: ${ENV, var="JOB_NAME"}, shows up fine. However ${ENV, var="serverName"} doesn't show at all.
I've tried variations such as...
${serverName}
${env.serverName}
...but they don't work either.
Any ideas how to use user defined environment variables like 'serverName' above in the email-ext plug-in?
Thanks & best regards, Richard.
You’re using single quotes, but only double quotes allow variables to be interpolated.
I would suggest you to use a Groovy script for rendering the email contents.
You can either use the predefined Groovy script like this:
emailext body: '''${SCRIPT, template="groovy-html.template"}'''
Or add your own template like described in the documentation. I couldn't figure our if it's possible to load that template from the workspace, but you could try it with:
emailext body: '''${SCRIPT, template="$WORKSPACE/groovy-html.template"}'''
The syntax for getting values from the environment or parameters when interpolating is:
${env.MY_ENVVAR}
${param.MY_BUILDPARAM}
(env and param is ja Groovy map holding all the values)
And for all other variables:
${varName}

How to send cucumber html report on mail

I have automation project which i'm running through Jenkins . With build successful or failure all html reports are being displayed after i click on link "Cucumber Feature Level Overview Report" .
Added dependency in pom
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>email-ext</artifactId>
<version>2.25</version>
</dependency>
Added code in jenkins job :-
Section : Editable Email Notification -> Default Content
${FILE,path="https://jenkins.company.com/dareProject/job/Automation_Jobs/job/Dare_Project_job/Cucumber_Steps_Level_Overview_Report/"}
The mail which i'm getting with error :-
ERROR: File 'https://jenkins.company.com/dareProject/job/Automation_Jobs/job/Dare_Project_job/Cucumber_Steps_Level_Overview_Report/' does not exist
And how to display report in Body Text of email ?
The mail which i'm getting with error
In path parameter you must use the location of file in filesystem relative to job's workspace, not the hyperlink to it!
And how to display report in Body Text of email ?
Set correct path in Default Content field and choose HTML (text/html) in Content Type field.

how to get fixed static images url for jenkins?

I generated the html webpage in jenkins jobs and try to success/failure icons inside.
But I noticed it is linked to the url with some random number 9b17c509 in the path
https://ci.jenkins.io/static/9b17c509/images/32x32/red.png
What I preferred is the fixed url for every jenkins instance like
https://ci.jenkins.io/static/images/32x32/blue.png
Any suggestion to solve it ?
BTW: I don't want to connect to external web for those images
9b17c509 looks like a cache.
We can use /images/32x32/blue.png
see https://ci.jenkins.io/images/32x32/blue.png
For a hudson.model.Result or the result name like "SUCCESS" you can get a ball icon with hudson.model.BallColor .
In Groovy
def iconUrl = (result as BallColor).getImageOf("16x16")

TFS build step WriteCustomSummaryInfo with Replace

How would I run "Replace" within WriteCustomSummaryInfo step.
I'm trying to display a link to an html report on the build summary:
Get drop location which I do:
\tfsbuild03\temp\Dev-Deployment\Dev-Deployment_20160115.22
replace all \ with / and append report.html at the end
I assume this is the way to do it.
I've tried the following but it doesn't work:
String.Format("dotCover [Coverage Results]file:({0})/{1}", Replace(DropLocation,"\","/"), "report.html")
EDIT
I figured it out. It's suppose to be this:
String.Format("dotCover [Coverage Results]file:({0})/{1}", DropLocation.Replace("\", "/"), "report.html")

Jenkins: add some text to the build summary

For each build in jenkins there's a page with a short summary of what happened in that build.
In my setup this page contains the list of commit messages that were added in this build, the name of the user who started that build and a note from the git plugin about the commit SHA1 and the branch name.
Is there a way for a normal script that I run as a build step to add something to this page? Is there a plugin which allows this?
I want to add a line with an HTML link to where the user can download this build.
You can use the Description Setter plugin to add a custom HTML description.
A quick example :)
Does it help?
UPDATE: here is the syntax for a Jenkins pipeline script
currentBuild.description = "<a href='http://stackoverflow.com'>Stackoverbuild build" + env.BUILD_ID + "</a>"
I used Badge Plugin for something like this.
Example:
def summary1 = createSummary(icon:"notepad.png", text:"started Builds:<br>")
summary1.appendText("myBuild1: SUCCESS<br>", false)
summary1.appendText("myBuild2: UNSTABLE<br>", false)

Resources