【问题标题】:Using Jenkins global credentials in a pipeline (Jenkinsfile)在管道中使用 Jenkins 全局凭证 (Jenkinsfile)
【发布时间】:2019-08-06 06:56:18
【问题描述】:

我目前正在 Jenkins 中自动化一个项目。我正在使用从源管理工具(在我的情况下为 GIT)读取和执行 Jenkinsfile 的管道。为此,我提供了 git URL 并使用“Jenkins Credentials Provider”提供凭据并执行构建。它读取 Jenkinsfile 并检查代码,但在下一阶段失败:

pipeline{
    agent any
    stages{
...
        stage('Cloning GIT Repo'){
            steps{
                echo 'Cloning the repository'
                git url: 'http://test.git'
            }
        }
...

它给出了错误:

No credentials specified

我有办法使用之前在 Jenkins UI 中指定的全局凭据吗?

【问题讨论】:

    标签: jenkins automation jenkins-pipeline


    【解决方案1】:

    你可以使用credentialsId参数

    git(
       url: 'http://test.git',
       credentialsId: 'jenkins-credentials',
       branch: "${branch}"
    )
    

    https://jenkins.io/doc/book/pipeline/jenkinsfile/#optional-step-arguments https://jenkins.io/doc/pipeline/examples/#push-git-repo

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-07-03
      • 1970-01-01
      • 1970-01-01
      • 2018-04-16
      相关资源
      最近更新 更多