NoSuchFileException in Jenkinsfile



我的 JenkinsFile 有问题。当我从同一目录加载时髦脚本时,我收到以下消息:

java.nio.file.NoSuchFileException:/u01/jenkins_slave/workspace/SPAC_SPAC_BUILD_POLIGON-1727/build/notificationManager.groovy

我尝试将路径更改为绝对路径"path(( +/build/notificationManager.groovy"或仅像"notificationManager.groovy"或"build/notificationManager.groovy"这样的文件路径。但是在所有这些情况下我都有同样的问题

我在代码中做什么:

def runner = load "build/notificationManager.groovy"
runner.notifyEmail("FAILURE", ${DEVELOPERS})

时髦功能

def notifyEmail(buildStatus, emailRecipients) {
try {
def icon = "✅"
def statusSuccess = true
def hasArtifacts = true
if(buildStatus != "SUCCESSFUL") {
icon = "❌"
statusSuccess = false
hasArtifacts = false
}
def body = emailTemplate([
"jenkinsText"   :   env.JOB_NAME,
"jenkinsUrl"    :   env.BUILD_URL,
"statusSuccess" :   statusSuccess,
"hasArtifacts"  :   hasArtifacts,
"downloadUrl"   :   "www.downloadurl.com"
]);
mail (to: emailRecipients.join(","),
subject: "${icon} [ ${env.JOB_NAME} ] [${env.BUILD_NUMBER}] - ${buildStatus} ",
body: body,
mimeType: 'text/html'
);
} catch (e){
println "ERROR SENDING EMAIL ${e}"
}
}

当您将 groovy 脚本加载到管道中时,groovy 文件必须在底部包含 'return this'。

def notifyEmail(buildStatus, emailRecipients) {
...
}
return this;

詹金斯文档:https://www.jenkins.io/doc/pipeline/steps/workflow-cps/#load-evaluate-a-groovy-source-file-into-the-pipeline-script

最新更新