Reputation: 11
I know this issue has been asked quite a number of times but the reasons are always different for occurrence of this hence asking again.
I recently upgraded my jenkins from 2.270 to 2.278 version.
After the upgrade when I tried running one of the pipelines I got the following error and the pipeline failed.
groovy.lang.MissingPropertyException: No such property: ERROR_MESSAGE for class: groovy.lang.Binding
The code snipplet where it points to look like this.
def <func2>(body) {
<some code>
stages {
stage('Initialise') {
steps {
buildName "${JOB_NAME}#${BUILD_NUMBER}"
script{
if (env.RELEASE == "1.0"){
env.ERROR_MESSAGE = "Please provide RELEASE"
currentBuild.result = 'FAILURE'
return
}
}
}
post {
unsuccessful {
notifySlack(
**message: "Deploy Initialise failed: ${ERROR_MESSAGE}",**
channel:"${slackDeployChannel}")
script{
env.DEPLOY = 'no'
}
}
}
}
and one more place the env.ERROR_MESSAGE is being called
def <func1>(arguments) {
try{
<SOME CODE>
return 0
}
catch (Exception e) {
env.ERROR_MESSAGE = e.getMessage()
return 0
}
}
both func1 and func2 are separate functions being called separately. Not sure if env.ERROR_MESSAGE is being initialised or not.
Any leads would be appreciated.
Cheers
Upvotes: 1
Views: 4891
Reputation: 2098
It's failing while groovy parsing "Deploy Initialise failed: ${ERROR_MESSAGE}"
as the scope of initializing ENV variable is limited.
It could be something like this :
define a variable and get it to assign and used where ever you want.
def errorMessage
def <func2>(body) {
<some code>
stages {
stage('Initialise') {
steps {
buildName "${JOB_NAME}#${BUILD_NUMBER}"
script{
if (env.RELEASE == "1.0"){
errorMessage = "Please provide RELEASE"
currentBuild.result = 'FAILURE'
return
}
}
}
post {
unsuccessful {
notifySlack(
**message: "Deploy Initialise failed: ${errorMessage}",**
channel:"${slackDeployChannel}")
script{
env.DEPLOY = 'no'
}
}
}
}
def <func1>(arguments) {
try{
<SOME CODE>
return 0
}
catch (Exception e) {
errorMessage = e.getMessage()
return 0
}
}
Upvotes: 1