无法验证Jenkins用户

yqkkidmi  于 2023-01-20  发布在  Jenkins
关注(0)|答案(2)|浏览(271)

我有一个Jenkinsfile,我想用它来配置Jenkins作业:

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

您知道如何解决此问题吗?

mftmpeh8

mftmpeh81#

可能是范围问题:
Warning: CredentialId "bitbucket-server:80b656edd20defd8141dfc97e777d544dcb6a11b7cbaf0b53963ee7f796f855b" could not be found
看起来用户范围的凭据无法被“git”管道步骤使用(参见JENKINS-44773: User Scoped credentials are not used by the "git" pipeline step关闭为“不修复”)
尝试在“system”范围或“folder”范围创建凭据,看看是否有效
Git Plugin Docs还指出“checkout步骤是首选的SCM checkout 方法,它提供的功能比git步骤多得多”。您可以给予一下:

checkout scmGit(
  branches: [[name: 'master']],
  userRemoteConfigs: [[credentialsId: 'bitbucket-server:80b656edd20defd8141dfc97e777d544dcb6a11b7cbaf0b53963ee7f796f855b',
    url: 'http://192.168.1.30:7990/scm/jen/helm.git']])

您可以在此处找到更多示例

xxhby3vn

xxhby3vn2#

你试过在Github中添加SSH公钥吗?我在Docker中使用Jenkins,所以我在容器中执行,然后我生成SSH密钥,将公钥添加到Github中,然后将私钥添加到Jenkins凭据中,这对我很有效。
如果不起作用,请尝试禁用默认Windows Git安装附带的凭据助手:
$ git config --系统--未设置凭据。helper

相关问题