簡體   English   中英

Jenkins 管道共享庫 - 使用 groovy.contains (git ls-remote) 時無法匹配

[英]Jenkins pipeline shared library - fails to get match when using groovy .contains (git ls-remote)

目前在嘗試匹配 git ls-remote 的結果時遇到問題。 目前正在測試是否存在一個 repo,但是在測試期間我有 6 個 repo 來測試一個不存在的 repo。 但是在運行代碼時,git ls-remote 報告沒有找到不存在的 repo,但 function 仍然被視為 true。

我已經嘗試了很多東西,包括將模式和 git ls-remote 的 output 設置為小寫。 以及修剪兩個結果。 以前我在腳本末尾沒有“|| true”,但是當它沒有找到一個 repo 時,它在到達 if 語句之前就失敗了。

def is_repository(repository_name)
{
    sshagent(['03876f99-2a9d-4980-b543-f8b478d4f1ec'])
    {
        String repository = sh( script: "git ls-remote git@bitbucket.org:<company_name>/${repository_name}.git || true", returnStdout: true)
        println(repository)
        String pattern = 'and the repository exists.'
        if(repository.contains(pattern))
        {
            println("Repository: " + repository_name + " not found")
            return false
        }
        else
        {
            println("Repository: " + repository_name + " found")
            return true
        }
    }
}

如果在 git ls-remote 的 output 中發現“未找到”,則預期 output 是否返回 false。

這是一個簡單的。 使用 jenkins sh()調用時,您可以定義returnStdout但不能定義Stderror ,因為Stderror只是打印到日志而不傳遞給變量。

暫無
暫無

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

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