简体   繁体   English

无法使用 Jenkins 管道登录到 Github

[英]Unable to logon to Github using Jenkins pipeline

I want to clone a github repository using Jenkins decriptive pipeline.我想使用 Jenkins 描述性管道克隆 github 存储库。 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.但是 Jenkins 无法登录 Github 帐户。 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.我也在网上搜索,有人提到可能是因为https。 However not clear how to resolve it.但是不清楚如何解决它。 Any idea what could i be doing wrong?知道我做错了什么吗?

So after some research I finally found the answer.所以经过一番研究,我终于找到了答案。 The problem was that Jenkins wasnt able to resolve the path of the Git executable.问题是 Jenkins 无法解析 Git 可执行文件的路径。

Go to Manage Jenkins -> Global Tool Configuration. Go 管理 Jenkins -> 全局工具配置。 Under the Git Tab, we need to give the absolute path of the Git executable.在 Git 选项卡下,我们需要给出 Git 可执行文件的绝对路径。 For a standard installation, the default path is C:\Program Files\Git\bin\git.exe .对于标准安装,默认路径是C:\Program Files\Git\bin\git.exe Save this and tried again.保存并重试。 Works.作品。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM