Get URL of Job in mail body in Jenkins

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)


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


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