【问题标题】:Credential error getting when adding SVN checkout in Jenkins pipeline在 Jenkins 管道中添加 SVN 结帐时出现凭据错误
【发布时间】:2019-05-16 06:21:35
【问题描述】:

我正在尝试逐步测试创建 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 svn jenkins-pipeline


    【解决方案1】:

    经过一番探索,我发现,需要使用 jenkins 的“withCredentials”选项将创建的凭据绑定到 uername 和密码变量。在阶段步骤中绑定后,需要将用户名和密码变量与我们将要使用“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
    

    【讨论】:

      猜你喜欢
      • 2015-08-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-07-29
      • 2022-06-16
      • 2020-05-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多