如何设置Jenkins从属代理的git用户

时间:2019-03-27 12:45:10

标签: git jenkins jenkins-pipeline

我有一个詹金斯(Jenkins)多分支管道作业,其结帐步骤如下:

    stage('Checkout'){
        steps{
            echo "Custom checkout: ${env.BRANCH_NAME} on ${pwd()}"
            checkout scm
        }
    }

当我在主服务器上运行它时,一切都很好。它使用我的凭据管理器中的凭据。

但是如果它被奴隶执行了,不知道为什么,但是我得到这个错误:

hudson.plugins.git.GitException: Command "git.exe fetch --no-tags --progress https://my.bitbucket/scm/Project/repository.git +refs/heads/feature/jenkins-build-with-custom-id:refs/remotes/origin/feature/jenkins-build-with-custom-id" returned status code 128:
stdout: 
stderr: fatal: Authentication failed for 'https://my.bitbucket/scm/Project/repository.git/'

我当时在想,它应该使用与我在git仓库上设置的相同的用户名密码,对吗?怎么了?我应该如何配置呢?

如果我执行git clone https://my.bitbucket/scm/Project/repository.git/,则会遇到相同的问题。如果我手动指定用户git clone https://jenkins@my.bitbucket/scm/Project/repository.git/可以,但是我看不到如何配置

1 个答案:

答案 0 :(得分:1)

您将需要使用凭据插件。 为您的bitbucket用户创建一个新凭据,并将其添加到git checkout

git(
   url: 'https://my.bitbucket/scm/Project/repository.git',
   credentialsId: 'my-bitbucket-user-credential',
   branch: "${branch}"
)

或者在使用多分支作业时在您的作业配置上使用凭据。无论如何,凭证插件是必经之路。不要尝试使用特定于git的方法,例如凭据助手,因为这在从属节点和主节点之间不起作用