jenkinsjenkins-pipelinejenkins-email-ext

How to pass string paramter in Jenkins pipeline to customize emailext?


I am trying to use the env parameters to customize the email body. But i not able to achieve it.

String parameter1 : NAMESPACE = abcd

Jenkins pipeline :

  agent{ label 'apps' }
  stages {
    stage("Checkout Sourcecode") {
                                xxxxxx
                    }
    stage('Create namespace'){
                                steps {
                                    sh """kubectl create namespace ${env.NAMESPACE}"""
                                        }
                                    }
    stage ("Clearing Workspace"){
                                steps{
                                    cleanWs()
                                }   
                            }
    }                       
    post {
    success {
        emailext body: '''Hi,
${env.NAMESPACE} is created.
Build is ${currentBuild.currentResult}              
Regards,
DT''', subject: 'Build ${BUILD_STATUS} - Build #${BUILD_NUMBER}', to: 'abc@xyz.com'
    }
}                       
}

Email output:

Subject: Build Success - Build #8

Hi,
${env.NAMESPACE} is created.
Build is ${currentBuild.currentResult}

Regards,
DT

Expected output is getting the value of NAMESPACE and currentBuild.currentResult. What am i doing wrong?


Solution

  • You need to use double-quotes (triple double-quotes) to use string interpolation. See here for more info. https://stackoverflow.com/a/37465198/10531450