簡體   English   中英

在Jenkins管道中添加SVN簽出時出現憑證錯誤

[英]Credential error getting when adding SVN checkout in Jenkins pipeline

我正在嘗試逐步測試創建Jenkins管道作業的過程。 為此,我正在嘗試首先為示例管道使用svn checkout進行測試。 我添加了聲明性管道並添加了svn checkout步驟。 但是我收到如下錯誤:

svn: E215004: No more credentials or we tried too many times.

我添加了如下的管道作業:

pipeline 
  {
    agent any
    stages 
      {
        stage ('Checkout') 
         {                 
           steps
             {
                sh 'svn co http://192.168.16.174/repository/pipeline'
             }
         }
     }
  }

我的觀察

根據我的觀察,我沒有在此處添加svn存儲庫憑據。 我是Jenkins和CI / CD的新手。 在學習時,我看到我們可以在Jenkins中創建憑據,並且可以在此處引用該ID。 但是我沒有確切的添加方法。 還有另一件事是,我計划將其添加到存儲在存儲庫根目錄中的Jenkinsfile中。

我的困惑

  1. 如果我在這里引用創建的憑據,我該如何引用?
  2. 如果我將我的Jenkinsfile保留在項目根目錄中以進行拉取,如果我在我的Jenkinsfile中添加憑據ID是否有任何問題?

我在這里與Jenkinsfile中的憑證有關的很多困惑。 如果我走錯了方向,請糾正我。

經過一番探索,我發現,需要使用jenkins的“ withCredentials”選項將創建的憑證綁定到uername和password變量。 在階段步驟中進行綁定之后,需要將用戶名和密碼變量與我們要使用“ sh”命令訪問的SVN存儲庫URL一起使用。 讓我補充一下我在這里所做的事情

pipeline 
{
    agent any
    stages 
        {
            stage ('Checkout') 
                {
                    steps
                        {

            withCredentials([[$class: 'UsernamePasswordMultiBinding',
                  credentialsId: '<credential-ID>',
                  usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD']]) {
    sh "svn co url --username $USERNAME --password $PASSWORD"
                                     }

                        }
                }
        }

}

並在控制台中獲得如下形式的輸出,如下所示:

Started by user admin
Running in Durability level: MAX_SURVIVABILITY
[Pipeline] Start of Pipeline
[Pipeline] node (hide)
Running on Jenkins in /var/lib/jenkins/workspace/kubernetes
[Pipeline] {
[Pipeline] stage
[Pipeline] { (Checkout)
[Pipeline] withCredentials
Masking only exact matches of $USERNAME or $PASSWORD
[Pipeline] {
[Pipeline] sh
+ svn co 'url' --username **** --password ****
Checked out revision 1.
[Pipeline] }
[Pipeline] // withCredentials
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
Finished: SUCCESS

暫無
暫無

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

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