To make my jenkins pipeline definition file more customizable, I try to use a maximum of variables.
When I try to use a variable in the mail or step command, jenkins throws this error:
java.lang.NoSuchMethodError: No such DSL method '$' found among [archive, bat, build, catchError, checkout, deleteDir, dir, echo, emailext, emailextrecipients, error, fileExists, git, input, isUnix, load, mail, node, parallel, properties, pwd, readFile, readTrusted, retry, sh, sleep, stage, stash, step, svn, timeout, timestamps, tool, unarchive, unstash, waitUntil, withCredentials, withEnv, wrap, writeFile, ws]
This is my pinyline definition file of my jenkins:
node {
def projectName = "JenkinsPipelineTest"
def notificationEmailRecipients = "aaa@domain.com"
def notificationEmailSender = "bbb@domain.com"
currentBuild.result = "SUCCESS"
try {
stage 'Finalization'
step([$class: 'ArtifactArchiver', artifacts: '*.zip, *.tar, *.exe, *.html', excludes: null])
step([$class: 'Mailer', notifyEveryUnstableBuild: true, recipients: ${notificationEmailRecipients}, sendToIndividuals: false])
}
catch (err) {
currentBuild.result = "FAILURE"
mail body: ${err},
charset: 'UTF-8',
from: ${notificationEmailSender},
mimeType: 'text/plain',
replyTo: ${notificationEmailSender},
subject: '"${projectName}" meet an error',
to: ${notificationEmailRecipients}
throw err
}
}
Is this normal or is it me who has an error in my definition file?