I want to create a first shared library to factorize my code in jenkins pipelines. For example, I use two notify methods for all my pipelines and I would like to have them in one location. So I searched how to create a shared library, and I have done this :
In my Notify class, my methods :
#!/usr/bin/env groovy
package fr.enterprise
class Notify {
static def notifySuccessful(String targetEnv) {
emailext (
subject: "SUCCESSFUL: New version deployed on $targetEnv",
body: """<html>
<body>
Go try it now! It's better when it's hot.
<br>
<br>With love,
<br>Your Dear Jenkins
</body>
</html>""",
recipientProviders: [[$class: 'RequesterRecipientProvider']]
)
}
static def notifyFailed(String targetEnv, String jobName, String buildUrl, String buildNumber) {
emailext (
subject: "FAILURE: Couldn't deploy new version on $targetEnv",
body: """<html>
<body>
I'm really sorry, but something went wrong when deploying Fides.
<br>
Please have a look at the logs here:
<br><a href="$buildUrl/console">$jobName [$buildNumber]</a>
<br>
<br>With love,
<br>Your Dear Jenkins
</body>
</html>""",
recipientProviders: [[$class: 'RequesterRecipientProvider']]
)
}
}
I import it in my pipeline code :
@Library('jenkins-shared-lib')
import fr.enterprise.Notify
When my pipeline want use one of my method, I have this error :
groovy.lang.MissingMethodException: No signature of method: java.lang.Class.emailext() is applicable for argument types: (java.util.LinkedHashMap)
What have I forgot ?
Here my code to call my methods :
success {
script {
Notify.notifySuccessful(params.TARGET_ENV)
}
}
failure {
script {
Notify.notifyFailed(params.TARGET_ENV, env.JOB_NAME, env.BUILD_URL, env.BUILD_NUMBER)
}
}