Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get URL of Job in mail body in Jenkins

I have Job in Jenkins that sends an email after the build with a HTML report in its body using email-ext plugin by setting Default content to this :

${FILE,path="absolute_path/index.html"}

I want to add to this (my body mail ) the URL of the build of this job. How is that possible ?

like image 398
HobbitOfShire Avatar asked Mar 14 '14 09:03

HobbitOfShire


People also ask

How do I get the current URL in Jenkins?

$BUILD_URL is the easiest way to do it, just add it in your Body mail and it will show the hyperlink of your latest build. Show activity on this post. Optionally specify the HTTP address of the Jenkins installation, such as http://yourhost.yourdomain/jenkins/.

What is Jenkins environment URL?

The Jenkins URL is a combination of your system's hostname and the port used by Jenkins. For instance, when logging in on your system using the default port 8080: http://localhost:8080/env-vars.html.


4 Answers

$BUILD_URL is the easiest way to do it, just add it in your Body mail and it will show the hyperlink of your latest build.

like image 84
HobbitOfShire Avatar answered Oct 29 '22 04:10

HobbitOfShire


Small update to this question:

First of all, you need to set Jenkins URL in your system configuration to access such URLs:

Jenkins -> Manage Jenkins -> Configure System -> Jenkins Location -> Jenkins URL

It set to http://localhost:8080/ by default (if you accepted this during initial start of Jenkins)

Optionally specify the HTTP address of the Jenkins installation, such as http://yourhost.yourdomain/jenkins/. This value is used to let Jenkins know how to refer to itself, ie. to display images or to create links in emails.

This is necessary because Jenkins cannot reliably detect such a URL from within itself.

Then you can access the build or job URLs via BUILD_URL or JOB_URL environment variables in your Groovy pipeline script.

For example:

println env.BUILD_URL
println env.JOB_URL

You also can find more such environment variables for your Jenkins instance on this page: http://localhost:8080/env-vars.html/ (replace localhost:8080 with your Jenkins URL)

like image 27
Sysanin Avatar answered Oct 29 '22 05:10

Sysanin


${PROJECT_URL} in the body of email will be resolved to a hyperlink to your job.

like image 25
izzekil Avatar answered Oct 29 '22 04:10

izzekil


Kindly Specified in the Default content under editable email configuration in Jenkins

//build_url is fetched the URL of Build //allure/ its append with URL for Allure reporting browser URL

${FILE,readFile("$BUILD_URL/allure/")

like image 30
Rahul Jain Avatar answered Oct 29 '22 06:10

Rahul Jain