Variable in jenkins pipeline
<p>In order to made my jenkins pipeline definition file more customizable, I try to use a maximum of variables.</p>

<p>When I try to use variable in <strong>mail</strong> or <strong>step</strong> instruction jenkins throw this error:</p>

<pre><code>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]
</code></pre>

<p>This is my jenkins pipleline definition file:</p>

<pre><code>#!groovy
node {

    //Define job context constants
    def projectName = "JenkinsPipelineTest"
    def notificationEmailRecipients = "aaa@domain.com"
    def notificationEmailSender = "bbb@domain.com"
    currentBuild.result = "SUCCESS"

    //Handle error that can occur in every satge
    try {

            //Some others stage...

            stage 'Finalization'
            step([$class: 'ArtifactArchiver', artifacts: '*.zip, *.tar, *.exe, *.html', excludes: null])
            step([$class: 'Mailer', notifyEveryUnstableBuild: true, recipients: ${notificationEmailRecipients}, sendToIndividuals: false])
    }
    catch (err) {
        //Set built state to error
        currentBuild.result = "FAILURE"

        //Send error notification mail
        mail body: ${err},
        charset: 'UTF-8',
        from: ${notificationEmailSender},
        mimeType: 'text/plain',
        replyTo: ${notificationEmailSender},
        subject: '"${projectName}" meet an error',
        to: ${notificationEmailRecipients}

        throw err
    }
}
</code></pre>

<p>It's normal or it's me that have an error in my definition file ?</p>