当前位置: 首页 > 知识库问答 >
问题:

使用jenkins管道作为代码从bitbucket私有存储库克隆

蒙胤
2023-03-14

我使用jenikins管道作为代码来克隆一个git项目,这个项目位于私有的比特桶存储库(stash存储库)中。

node {  
//checkout from master  
stage 'checkout'  
   withCredentials([[$class: 'UsernamePasswordMultiBinding', credentialsId: 'MyID', usernameVariable: 'GIT_USERNAME', passwordVariable: 'GIT_PASSWORD']]) {  

      git url: 'https://paulrda@devMyCompany.org/stash/scm/test_automation.git' , branch: 'development'   
   }  
}  

“MyID”是凭证ID,并且我的用户名和密码正确。我将凭证保存在jenkins的全局凭证功能中。但是我在构建jenkins任务时遇到了这个错误。

ERROR: Error fetching remote repo 'origin'
hudson.plugins.git.GitException: Failed to fetch from https://paulrda@devMyCompany.org/stash/scm/test_automation.git
    at hudson.plugins.git.GitSCM.fetchFrom(GitSCM.java:803)
    at hudson.plugins.git.GitSCM.retrieveChanges(GitSCM.java:1063)
    at hudson.plugins.git.GitSCM.checkout(GitSCM.java:1094)
    at org.jenkinsci.plugins.workflow.steps.scm.SCMStep.checkout(SCMStep.java:109)
    at org.jenkinsci.plugins.workflow.steps.scm.SCMStep$StepExecutionImpl.run(SCMStep.java:83)
    at org.jenkinsci.plugins.workflow.steps.scm.SCMStep$StepExecutionImpl.run(SCMStep.java:73)
    at org.jenkinsci.plugins.workflow.steps.AbstractSynchronousNonBlockingStepExecution$1$1.call(AbstractSynchronousNonBlockingStepExecution.java:47)
    at hudson.security.ACL.impersonate(ACL.java:221)
    at org.jenkinsci.plugins.workflow.steps.AbstractSynchronousNonBlockingStepExecution$1.run(AbstractSynchronousNonBlockingStepExecution.java:44)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
Caused by: hudson.plugins.git.GitException: Command "git fetch --tags --progress https://paulrda@devMyCompany.org/stash/scm/test_automation.git +refs/heads/*:refs/remotes/origin/*" returned status code 128:
stdout: 
stderr: fatal: Authentication failed for 'https://paulrda@devMyCompany.org/stash/scm/test_automation.git/'

    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:1745)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandWithCredentials(CliGitAPIImpl.java:1489)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.access$300(CliGitAPIImpl.java:64)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$1.execute(CliGitAPIImpl.java:315)
    at hudson.plugins.git.GitSCM.fetchFrom(GitSCM.java:801)

在我的mac机器下我paulrda帐户我可以成功克隆我的项目使用jenkins管道脚本,但当我改变到另一个帐户和运行jenkins我得到这个错误。

我的配置。
Jenkins版本:2.19.2凭证插件:2.1.8
Git插件:3.0.0
Git客户端插件:2.1.0

共有1个答案

颛孙国源
2023-03-14

它无法进行身份验证,因为您没有正确地将凭据传递给git调用。

由于您使用的是Git插件而不是shell命令,因此根本不需要使用带有凭据的。您可以将credentialsId直接传递到git调用,如下所示:

stage('checkout') {
    git credentialsId: 'MyID', url: 'https://devMyCompany.org/stash/scm/test_automation.git', branch: 'development'
}
 类似资料:
  • 问题内容: Jenkins中建立一个托管在bitbucket上的项目时,我将在URL字段中输入什么? 该存储库是私有的。 问题答案: 我对Jenkins并不熟悉,但是Bitbucket允许您通过https克隆git存储库,https可以接受密码作为url的一部分,如下所示:

  • 问题内容: 我无法让Jenkins通过SSH在BitBucket上克隆git存储库。出现以下消息失败: 采取的步骤 创建一个SSH密钥对 将公共密钥添加为BitBucket上存储库的部署密钥 在Jenkins Credentials Manager插件中安装SSH密钥和用户名(尝试过’git’和我的BB帐户名) 尝试使用URL的形式在构建中克隆存储库 我也尝试过不使用凭据管理器并手动将密钥安装在中

  • 我在Linux(arch)上,试图使用ssh密钥在本教程之后使用私有bitbucket git存储库配置Spring Cloud Config,但我一直收到错误: 现在,根据教程,它应该工作: 如果您不使用HTTPS和用户凭据,SSH也应该在您将密钥存储在默认目录(~/. ssh)中并且uri指向SSH位置时开箱即用,例如"git@github.com:配置/云-配置”。重要的是~/. ssh/k

  • 问题内容: 我已经在Bitbucket服务器中将Webhook安装到Jenkins for Bitbucket 插件。主要目标是在提交后将触发詹金斯构建。 安装后,我启用了插件:jenkins-url:https:// url / jenkins ssh:ssh @ git ..(在SCM插件jenkins作业中使用了相同的命令)。 詹金斯工作正常(git clone等正常工作),但插件不工作。当

  • 目前,我们使用JJB编译Jenkins作业(大部分已经是管道),以便配置大约700个作业,但JJB2似乎无法很好地扩展以构建管道,我正在寻找一种方法将其从等式中删除。 我主要希望能够将所有这些管道存储在一个集中的存储库中。 请注意,在我们的用例中,将CI配置(jenkins文件)保存在每个存储库和分支中是不可能的,我们需要将所有管道保存在一个“jenkins jobs.git”repo中。

  • 问题内容: 我是github组织的所有者,可以访问所有存储库。其中一些是私人的,其他则是公共的。我正在尝试将Jenkins设置为在向组织的任何存储库发出拉取请求时触发构建。问题是我有一个外部系统,每当发出请求时,它就会通过github webhooks通知。我必须将Jenkins与此系统集成在一起。该系统还可以通过api请求触发到Jenkins的通知。(https://python- jenkin