Issue
I like to commit my Jenkins email script to my working copy and use it with Email-ext.
So I wrote something like :
pipeline {
agent any
stages {
stage('Build') {
steps {
echo 'Building...'
}
}
}
post {
always {
echo 'Sending email...'
emailext body: '''${SCRIPT, template="${WORKSPACE}\\Src\\Scripts\\Jenkins\\groovy-html2.template"}''',
mimeType: 'text/html',
subject: "[Leeroy Jenkins] ${currentBuild.fullDisplayName}",
to: "[email protected]",
replyTo: "[email protected]",
recipientProviders: [[$class: 'CulpritsRecipientProvider']]
}
}
}
But I get the following mail: Groovy Template file [${WORKSPACE}SrcScriptsJenkinsgroovy-html2.template] was not found in $JENKINS_HOME/email-templates.
Solution
Solve it by manually overriding the file using command line:
pipeline {
agent any
stages {
stage('Build') {
steps {
echo 'Building...'
}
}
}
post {
always {
echo 'Sending email...'
bat "copy /Y ${WORKSPACE}\\Src\\Scripts\\Jenkins\\groovy-html2.template \"${JENKINS_HOME}\\email-templates\\groovy-html2.template\""
emailext body: '''${SCRIPT, template="${WORKSPACE}\\Src\\Scripts\\Jenkins\\groovy-html2.template"}''',
mimeType: 'text/html',
subject: "[Leeroy Jenkins] ${currentBuild.fullDisplayName}",
to: "[email protected]",
replyTo: "[email protected]",
recipientProviders: [[$class: 'CulpritsRecipientProvider']]
}
}
}
A bit crude, but it works.
Answered By - user3360767