I am currently implementing Slack notifications for our build and deploy jobs but seem to be running into an issue at the end of the job. The build runs successfully, but it complains at the end that the script is incorrect with the following error (partial):
hudson.remoting.ProxyException: groovy.lang.MissingMethodException: No signature of method: java.util.LinkedHashMap.call() is applicable for argument types: (org.jenkinsci.plugins.workflow.cps.CpsClosure2) values: [org.jenkinsci.plugins.workflow.cps.CpsClosure2@48e051e9]
Possible solutions: wait(), any(), wait(long), any(groovy.lang.Closure), take(int), each(groovy.lang.Closure)
I am using the try/catch/finally method and probably have them in the wrong place though I have looked at example snippets and this is pretty close to what I have seen though something seems missing and I'm just not seeing it. This is the second half of the code which details the run:
nodePod(name: "ctl-${envName}-build", type: "maven-stable"){
try {
catchError(buildResult: 'FAILURE', stageResult: 'FAILURE') {
buildJava(
version: "${params.version}",
serviceName: "catalog",
sonarQube: "true",
skipTest: "false",
buildOnly: "false",
triggerDeploy: "true",
withAPM: "true",
qualityGate: "true",
deployJobName: "../deploy/${env.JOB_BASE_NAME}"
)
}
} catch (e) {
// If there was an exception thrown, the build failed
currentBuild.result = 'FAILURE'
throw e
} finally {
// Notify build job result to Slack channel
def COLOR_MAP = ['SUCCESS': '#229E3B',
'FAILURE': '#E01215',
'UNSTABLE': '#E8CF2A',
'ABORTED': '#FF9933']
{
MESSAGE_MAP = """
${currentBuild.currentResult}: `${env.JOB_NAME}` #${env.BUILD_NUMBER} - <${env.BUILD_URL}|Details>
Duration: ${currentBuild.durationString.minus(' and counting')}
"""
}
slackSend color: COLOR_MAP[currentBuild.currentResult],
message: MESSAGE_MAP
}
}
Unfortunately since we are using a Pipeline job, the Slack notification section is not accessible so therefore they need to be in the script which has proven to be a bit of a challenge. Any feedback would be appreciated. Thanks.