I am trying to create a shared library for Jenkins.
I tried to create a script to send notifications through Teams, this is the code:
def call(String buildStatus = null, String webook) {
def status
def color
switch(buildStatus) {
case { null || "SUCCESS" }:
status = "Success"
color = "Green"
break
case "FAILED":
status = "Failed"
color = "Red"
break
default:
status = null
color = null
}
println(status + " " + color)
}
The problem is that if I try to run it in my pipeline I get this exception:
Error when executing always post condition:
CpsCallableInvocation{methodName=call, call=com.cloudbees.groovy.cps.impl.CpsClosureDef@1ba818f1, receiver=org.jenkinsci.plugins.workflow.cps.CpsClosure2@22438c5c, arguments=[SUCCESS]}
This is the pipeline I am testing:
pipeline{
agent{
label 'linux'
}
stages{
stage('Build') {
steps{
...snip...
}
}
}
post {
always {
notifyTeams(currentBuild.result, "XXXXX")
}
}
}
What am I doing wrong? Thanks!