Home > OS >  Cannot authenticate Jenkins user
Cannot authenticate Jenkins user

Time:01-18

I have this Jenkinsfile which I want to use to configure Jenkins job:

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
            }
        }
    }
}

I used these configured credentials:

enter image description here

But when I run the job I get:

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

Do you know how I can fix this issue?

CodePudding user response:

have you tried adding SSH Public Key to Github?. I use Jenkins in Docker so I exec into the container, then I generated ssh keys, added the public key to Github and then added the Private keys to Jenkins credentials, and this worked for me.

If that doesn't work then try disabling the credential helper that comes with the default Windows Git installation:

$ git config --system --unset credential.helper

CodePudding user response:

It could be a scope problem:

Warning: CredentialId "bitbucket-server:80b656edd20defd8141dfc97e777d544dcb6a11b7cbaf0b53963ee7f796f855b" could not be found

It looks like user scoped credentials can't be used by the "git" pipeline step (see JENKINS-44773: User Scoped credentials are not used by the "git" pipeline step closed as "Won't fix")

Try creating the credentials at "system" scope or "folder" scope to see if it works

Git Plugin Docs also say that "The checkout step is the preferred SCM checkout method. It provides significantly more functionality than the git step". You could give it a try:

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

You can find more examples here

  • Related