Jenkins用户认证失败求助:拉取Bitbucket Git仓库失败
问题:Jenkins拉取Bitbucket Git仓库认证失败
配置的Jenkinsfile
pipeline { agent any stages { stage('Download Helm Charts') { steps { sh "echo 'Downloading Helm Charts from Bitbucket repository...'" // configure credentials under http://192.168.1.28:8080/user/test/credentials/ and put credentials ID git credentialsId: 'bitbucket-server:80b656edd20defd8141dfc97e777d544dcb6a11b7cbaf0b53963ee7f796f855b', url: 'http://192.168.1.30:7990/scm/jen/helm.git', branch: 'master' // not sure do I need to point the root folder of the Helm repository or only the single chart } } stage('Test Kubernetes version') { steps { sh "echo 'Checking Kubernetes version..'" // How to do remote test of kubernetes version } } } }
运行时报错信息
The recommended git tool is: NONE Warning: CredentialId "bitbucket-server:80b656edd20defd8141dfc97e777d544dcb6a11b7cbaf0b53963ee7f796f855b" could not be found. > git rev-parse --resolve-git-dir /var/lib/jenkins/workspace/jenkins_master/.git # timeout=10 Fetching changes from the remote Git repository > git config remote.origin.url http://192.168.1.30:7990/scm/jen/helm.git # timeout=10 Fetching upstream changes from http://192.168.1.30:7990/scm/jen/helm.git > git --version # timeout=10 > git --version # 'git version 2.34.1' > git fetch --tags --force --progress -- http://192.168.1.30:7990/scm/jen/helm.git +refs/heads/*:refs/remotes/origin/* # timeout=10 ERROR: Error fetching remote repo 'origin' hudson.plugins.git.GitException: Failed to fetch from http://192.168.1.30:7990/scm/jen/helm.git at hudson.plugins.git.GitSCM.fetchFrom(GitSCM.java:1003) at hudson.plugins.git.GitSCM.retrieveChanges(GitSCM.java:1245) at hudson.plugins.git.GitSCM.checkout(GitSCM.java:1309) at org.jenkinsci.plugins.workflow.steps.scm.SCMStep.checkout(SCMStep.java:129) at org.jenkinsci.plugins.workflow.steps.scm.SCMStep$StepExecutionImpl.run(SCMStep.java:97) at org.jenkinsci.plugins.workflow.steps.scm.SCMStep$StepExecutionImpl.run(SCMStep.java:84) at org.jenkinsci.plugins.workflow.steps.SynchronousNonBlockingStepExecution.lambda$start$0(SynchronousNonBlockingStepExecution.java:47) at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515) at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264) at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) at java.base/java.lang.Thread.run(Thread.java:829) Caused by: hudson.plugins.git.GitException: Command "git fetch --tags --force --progress -- http://192.168.1.30:7990/scm/jen/helm.git +refs/heads/*:refs/remotes/origin/*" returned status code 128: stdout: stderr: fatal: Authentication failed for 'http://192.168.1.30:7990/scm/jen/helm.git/' at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2734) at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandWithCredentials(CliGitAPIImpl.java:2111) at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$1.execute(CliGitAPIImpl.java:623) at hudson.plugins.git.GitSCM.fetchFrom(GitSCM.java:1001) ... 11 more
解决步骤
1. 核对凭证ID
错误日志明确提示指定的凭证ID不存在,按以下操作:
- 登录Jenkins,进入
http://192.168.1.28:8080/user/test/credentials/,找到对应Bitbucket的凭证,复制系统生成的真实凭证ID(不要用显示名称)。 - 替换Jenkinsfile中
git步骤的credentialsId值为正确的ID。
2. 确认凭证类型匹配
当前用HTTP协议访问Git仓库,必须使用用户名+密码类型的凭证(或Bitbucket个人访问令牌,令牌作为密码字段)。如果配置的是SSH密钥凭证,会导致认证失败。
3. 验证凭证权限
- 在Jenkins代理节点上执行
git clone http://192.168.1.30:7990/scm/jen/helm.git,输入凭证中的用户名和密码,确认能否成功克隆。 - 若手动克隆失败,需去Bitbucket检查该账号是否有仓库访问权限,或重置密码/令牌。
4. 检查凭证作用域
确保凭证的作用域是全局,或当前Jenkins任务所在的文件夹/任务本身可见的作用域。私有用户作用域的凭证可能无法被任务调用。
5. 可选:简化SCM配置
如果已在Jenkins任务配置页面关联了该Git仓库和对应凭证,可将Pipeline中的git步骤替换为checkout scm,避免手动输入凭证ID出错。
关于Kubernetes版本测试的补充
要远程检测Kubernetes版本,需在Jenkins代理上配置kubeconfig:
- 将kubeconfig文件作为凭证存储在Jenkins中。
- 在Pipeline步骤中将kubeconfig复制到代理的
~/.kube/config路径。 - 执行
sh "kubectl version --short"命令获取版本信息。
内容的提问来源于stack exchange,提问作者Peter Penzov
相关产品推荐
相关产品推荐

