1

Here's one environment variable MODEL in my Jenkins declarative script. But I am not able to use this MODEL variable into the email body. Though it is working fine in the email subject!

pipeline {
  agent any
  stages {
    stage(‘Test’) {
        environment {            
            MODEL = “Some ML Model v1.2.3”
        }
        steps {
          ...
        }
        post {
            always {
                emailext attachLog: true,
                    attachmentsPattern: ‘**/reports/*.html’,
                    mimeType: “text/html”,
                    to: 'myemail@company.com’,
                    subject: “Test - ${env.MODEL} Build [${env.BUILD_NUMBER}]“,
                    body: '''<html>
                        <p><b>Regression Test Report</b></p>
                        <p>$MODEL</p>
                        <p>${MODEL}</p>
                        <p>"${MODEL}"</p>
                        <p>"${env.MODEL}"</p>
                        <p>""'${MODEL}'""</p>
                        <p>""'${env.MODEL}'""</p>
                        <p>"""${env.MODEL}"""</p>
                        <p>${ENV,var="MODEL"}</p>
                        <p>"${ENV,var="MODEL"}"</p>
                        <p>Build URL: $BUILD_URL</p>
                        <p>Build Status: $BUILD_STATUS</p>                        
                        <br />
                        <p><b>Console Output</b></p>
                        <pre>${BUILD_LOG_REGEX, regex="^.*test session starts.*$", showTruncatedLines=false}</pre>
                        <pre>${BUILD_LOG_EXCERPT, start="^.*test.*==$", end="^.*in.*==$"}</pre>
                        ...
                        </html>'''
                }
            }
        }
    }
}

I have tried multiple things as shown, but this script is just producing following email body:

enter image description here

Also went through several links like the following but still did not get the drill. Please suggest something.

User
  • 4,023
  • 4
  • 37
  • 63

2 Answers2

0

For such cases you need to use triple double quotes when defining template:

body:"""
  var: ${var}
  envvar: ${env.VAR}
"""
Mr. V.K.
  • 78
  • 1
  • 5
0

I tryed '''+VAR+''' and it's work fine!

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jul 25 '22 at 00:23