Get URL of Job in mail body in Jenkins
Asked Answered
R

4

27

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 ?

Robbierobbin answered 14/3, 2014 at 9:43 Comment(0)
R
54

$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.

Robbierobbin answered 14/3, 2014 at 10:35 Comment(2)
$BUILD_URL returns localhost:8080/job/TestProject/16 and $PROJECT_URL returns localhost:8080/job/TestProjectMarna
Configure JENKINS_URL: Configure System > Jenkins URLTedmann
L
24

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)

Lame answered 25/9, 2018 at 9:0 Comment(0)
A
1

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

Annunciation answered 17/3, 2014 at 15:38 Comment(1)
I get null for PROJECT_URLSpatial
L
1

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/")

Leastwise answered 15/1, 2019 at 11:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.