Jenkins environment variables email template

In Jenkins, you can use environment variables in email templates to dynamically generate email content. Here are some common environment variables you can use:

  1. BUILD_URL: The URL of the Jenkins build.
  2. BUILD_ID: The ID of the Jenkins build.
  3. BUILD_NUMBER: The number of the Jenkins build.
  4. JOB_NAME: The name of the Jenkins job.
  5. JOB_URL: The URL of the Jenkins job.
  6. PROJECT_NAME: The name of the Jenkins project.
  7. TEST_RESULT: The result of the test (e.g. "Passed", "Failed", etc.).
  8. TEST_REPORT: The test report URL.
  9. BUILD_CAUSE: The cause of the build (e.g. "Triggered by SCM changes", etc.).
  10. BUILD_CAUSE_USER: The user who triggered the build.

You can use these environment variables in your email template by wrapping them in ${...}. For example:

Here's an example email template that uses some of these environment variables:

Subject: Jenkins Build ${BUILD_NUMBER} - ${JOB_NAME}

Dear ${EMAIL_RECIPIENT},

This email is generated by Jenkins to notify you of the build status.

Build URL: ${BUILD_URL}
Build ID: ${BUILD_ID}
Job Name: ${JOB_NAME}
Job URL: ${JOB_URL}

The build was triggered by ${BUILD_CAUSE} and was caused by ${BUILD_CAUSE_USER}.

The test result is: ${TEST_RESULT}

You can view the test report at: ${TEST_REPORT}

Best regards,
Jenkins

You can customize this template to fit your needs and add or remove environment variables as necessary.

To use this template in your Jenkins job, follow these steps:

  1. Go to your Jenkins job's configuration page.
  2. Click on the "Post-build Actions" section.
  3. Click on the "Email" post-build action.
  4. In the "Email Recipient" field, enter the email address of the recipient.
  5. In the "Email Template" field, enter the template above.
  6. Click "Save" to save the changes.

When the build is complete, Jenkins will send an email to the recipient with the generated content.