簡體   English   中英

Jenkins-如何將變量傳遞給Bitbucket狀態通知插件?

[英]Jenkins - How to pass variables to Bitbucket status notify plugin?

我正在嘗試將變量傳遞給Bitbucketstatusnotify插件,但是它不起作用。 我嘗試了不同的迭代,並使用轉義字符等都無濟於事。 這有可能嗎? 如果是,怎么辦?

我的詹金斯管道片段如下:

REPO_SLUG = sh(script: "echo ${GIT_URL} | grep -oP '(?<=/).*[^.git]'", returnStdout: true)

// Update Bitbucket commit build status to In Progress  
bitbucketStatusNotify(buildState: 'INPROGRESS', repoSlug: "${REPO_SLUG}", commitId: "${GIT_COMMIT}")

try {

//build code here

// Update Bitbucket commit build status to Successful  
bitbucketStatusNotify(buildState: 'SUCCESSFUL', repoSlug: "${REPO_SLUG}", commitId: "${GIT_COMMIT}")


} catch (Exception e) {

echo 'Error occured: ' + e

// Update Bitbucket commit build status to Failed  
bitbucketStatusNotify(buildState: 'FAILED', repoSlug: "${REPO_SLUG}", commitId: "${GIT_COMMIT}")

}

注意 ,GIT_COMMIT是詹金斯環境變量。 我試着在這些變量上回顯,並按預期看到正確的值,但是將它們傳遞給此插件似乎不起作用。

請使用該腳本:
導入hudson.tasks.test.AbstractTestResultAction

node {
    stage 'Checkout'
        notifyBitbucket('INPROGRESS')
        cleanWs()
        checkout scm
    enter code here
    stage 'Build'
        bat "nuget restore \"${workspace}/PlaygroundForVaults.sln\""
        bat "\"C:/Program Files/dotnet/dotnet.exe\" restore \"${workspace}/PlaygroundForVaults.sln\""
        bat "\"C:/Program Files/dotnet/dotnet.exe\" build \"${workspace}/PlaygroundForVaults.sln\""
    stage 'UnitTests'
        bat returnStatus: true, script: "\"C:/Program Files/dotnet/dotnet.exe\" test \"${workspace}/PlaygroundForVaults.sln\" --logger \"trx;LogFileName=unit_tests.xml\" --no-build"
        step([$class: 'MSTestPublisher', testResultsFile:"**/unit_tests.xml", failOnError: true, keepLongStdio: true])
        def allTestPassed = allTestPass()
        if(allTestPassed == false)
        {
            notifyBitbucket('FAILED')
            assert false
        }
        else
        {
            notifyBitbucket('SUCCESS')
        }
}
def allTestPass() {
    def testStatus = ""
    def allTestPass = 0
    AbstractTestResultAction testResultAction = currentBuild.rawBuild.getAction(AbstractTestResultAction.class)
    if (testResultAction != null) {
        def total = testResultAction.totalCount
        def failed = testResultAction.failCount
        def skipped = testResultAction.skipCount
        def passed = total - failed - skipped
        testStatus = "Test Status:\n  Passed: ${passed}, Failed: ${failed} ${testResultAction.failureDiffString}, Skipped: ${skipped}"
        if (failed == 0) {
            currentBuild.result = 'SUCCESS'
        }
        allTestPass = (failed == 0)
    }
    else
    {
        testStatus = "Didn't find any tests..."
        allTestPass = false
    }
    println testStatus
    return allTestPass
}
def notifyBitbucket(String state) {
    println "Notify Bitbucket With " + state + ", Commit = " + "${Commit}"
    if('SUCCESS' == state || 'FAILED' == state) {
        currentBuild.result = state         // Set result of currentBuild !Important!
    }

    notifyBitbucket commitSha1: '${Commit}', 
                    credentialsId: 'Bitbucket_PG_Global_For_Notification_User_Pass', 
                    disableInprogressNotification: false, 
                    considerUnstableAsSuccess: false, 
                    ignoreUnverifiedSSLPeer: true, 
                    includeBuildNumberInKey: false, `enter code here`
                    prependParentProjectKey: false, 
                    projectKey: '', 
                    stashServerBaseUrl: '<your server ip>:7990'

暫無
暫無

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

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