1
votes

I am using email ext in the jenkins pipeline script with email body reference to a file. I want to know how to pass user defined variable. Ex:- I want to pass the variables "mySonarURL" and "myData" to the HTML file.

    def committer = getGitCommitterEmail()
    def mySonarURL = "My Sonar URL"
    def myData = "My Data"

    emailext (
        to: committer,
        subject: "Jenkins Build ${branchName} #${env.BUILD_NUMBER} [${currentBuild.result}]",
        body: '${FILE,path="email.html"}',
        mimeType: 'text/html'
    )
}

HTML file

<table>
    <tr><th>My Data:</th><td>"${myData}"</td></tr>
    <tr><th>Sonar URL:</th><td><a href="${mySonarURL}">Sonar URL</a></td></tr>
</table>

I have tried using as above HTML file but they were returning just the string "${myData}" and "${mySonarURL}"

1

1 Answers

-1
votes

Mention type as Script in body of mail as guided in official Jenkins wiki

body: '${SCRIPT, template="email.html"}'