簡體   English   中英

Jenkins共享庫依賴項未找到

[英]Jenkins shared library dependency not found

我想創建一個第一個共享庫來分解jenkins管道中的代碼。 例如,我對所有管道使用兩種通知方法,我希望將它們放在一個位置。 所以我搜索了如何創建共享庫,我已經這樣做了:

項目樹

在我的Notify類中,我的方法:

#!/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']]
        )
    }
}

我在管道代碼中導入它:

@Library('jenkins-shared-lib')
import fr.enterprise.Notify

而在詹金斯: 詹金斯配置

當我的管道想要使用我的方法之一時,我有這個錯誤:

groovy.lang.MissingMethodException: No signature of method: java.lang.Class.emailext() is applicable for argument types: (java.util.LinkedHashMap)

我忘記了什么?

這里我的代碼調用我的方法:

success {
  script {
    Notify.notifySuccessful(params.TARGET_ENV)
  }
}
failure {
  script {
    Notify.notifyFailed(params.TARGET_ENV, env.JOB_NAME, env.BUILD_URL, env.BUILD_NUMBER)
  }
}

(or the one you are using). 來自Jenkins docs: (或者你正在使用的那些)之類的步驟。 為了做到這一點,你應該做這樣的事情

Notify.groovy

#! /usr/bin groovy

def notifySuccessful(String targetEnv) {
        your code
}
return this

注意使用return this
然后從管道中可以使用它的聲明

@Library('jenkins-shared-lib') _


def notify = new fr.enterprise.Notify()
notify.notifySuccessful("var")

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM