Unable to logon to Github using Jenkins pipeline

2k views Asked by At

I want to clone a github repository using Jenkins decriptive pipeline. I use the following code :

pipeline {
   agent any
   stages {
    stage('Checkout') {
      steps {
        script {
           // The below will clone your repo and will be checked out to master branch by default.
           git credentialsId: 'jenkins-user-github', url: 'https://github.com/aakashsehgal/FMU'
           // Do a ls -lart to view all the files are cloned. It will be clonned. This is just for you to be sure about it.
           //bat "ls -lart ./*" 
           // List all branches in your repo. 
           bat "git branch -a"
           // Checkout to a specific branch in your repo.

          }
       }
    }
  }
}

But Jenkins cannot log on to the Github account. I have double checked the credentials and they are correct. Here is the error :

Started by user Aakash Sehgal
Running in Durability level: MAX_SURVIVABILITY
[Pipeline] Start of Pipeline
[Pipeline] node
Running on Jenkins in C:\Program Files (x86)\Jenkins\workspace\GitHub
[Pipeline] {
[Pipeline] stage
[Pipeline] { (Checkout)
[Pipeline] script
[Pipeline] {
[Pipeline] git
using credential jenkins-user-github
 > git.exe rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
 > git.exe config remote.origin.url https://github.com/aakashsehgal/FMU # timeout=10
Fetching upstream changes from https://github.com/aakashsehgal/FMU
 > git.exe --version # timeout=10
using GIT_ASKPASS to set credentials 
 > git.exe fetch --tags --force --progress -- https://github.com/aakashsehgal/FMU +refs/heads/*:refs/remotes/origin/* # timeout=10
ERROR: Error fetching remote repo 'origin'
hudson.plugins.git.GitException: Failed to fetch from https://github.com/aakashsehgal/FMU
    at hudson.plugins.git.GitSCM.fetchFrom(GitSCM.java:909)
    at hudson.plugins.git.GitSCM.retrieveChanges(GitSCM.java:1131)
    at hudson.plugins.git.GitSCM.checkout(GitSCM.java:1167)
    at org.jenkinsci.plugins.workflow.steps.scm.SCMStep.checkout(SCMStep.java:124)
    at org.jenkinsci.plugins.workflow.steps.scm.SCMStep$StepExecutionImpl.run(SCMStep.java:93)
    at org.jenkinsci.plugins.workflow.steps.scm.SCMStep$StepExecutionImpl.run(SCMStep.java:80)
    at org.jenkinsci.plugins.workflow.steps.SynchronousNonBlockingStepExecution.lambda$start$0(SynchronousNonBlockingStepExecution.java:47)
    at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
    at java.util.concurrent.FutureTask.run(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
Caused by: hudson.plugins.git.GitException: Command "git.exe fetch --tags --force --progress -- https://github.com/aakashsehgal/FMU +refs/heads/*:refs/remotes/origin/*" returned status code 128:
stdout: 
stderr: Logon failed, use ctrl+c to cancel basic credential prompt.
warning: invalid credential line: get
remote: Invalid username or password.
fatal: Authentication failed for 'https://github.com/aakashsehgal/FMU/'

    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2430)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandWithCredentials(CliGitAPIImpl.java:2044)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.access$500(CliGitAPIImpl.java:81)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$1.execute(CliGitAPIImpl.java:569)
    at hudson.plugins.git.GitSCM.fetchFrom(GitSCM.java:907)
    ... 11 more
[Pipeline] }
[Pipeline] // script
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
ERROR: Error fetching remote repo 'origin'
Finished: FAILURE

I also searched online and someone mentions that it could be because of https. However not clear how to resolve it. Any idea what could i be doing wrong ?

1

There are 1 answers

0
Vishal Rawat On

So after some research I finally found the answer. The problem was that Jenkins wasnt able to resolve the path of the Git executable.

Go to Manage Jenkins -> Global Tool Configuration. Under the Git Tab, we need to give the absolute path of the Git executable. For a standard installation, the default path is C:\Program Files\Git\bin\git.exe. Save this and tried again. Works.