Jenkins:获取远程仓库时出错 'origin'

Jenkins: Error fetching remote repo 'origin'

我是 Jenkins 的新用户,我收到了以下错误 ERROR: Error fetching remote repo 'origin',我在 Stack 上阅读了一些关于此错误的帖子,其中一些在 /tmp 中提到了“容量磁盘”,其他人说的是工作区默认值,但其中 none 帮助我解决了这个问题。

ERROR: Error fetching remote repo 'origin'
hudson.plugins.git.GitException: Failed to fetch from https://github.com/not-show-my-url.git
    at hudson.plugins.git.GitSCM.fetchFrom(GitSCM.java:996)
    at hudson.plugins.git.GitSCM.retrieveChanges(GitSCM.java:1237)
    at hudson.plugins.git.GitSCM.checkout(GitSCM.java:1297)
    at org.jenkinsci.plugins.workflow.steps.scm.SCMStep.checkout(SCMStep.java:125)
    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[=11=](SynchronousNonBlockingStepExecution.java:47)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)
Caused by: hudson.plugins.git.GitException: Command "git fetch --tags --progress -- https://github.com/thiagolmoraes/Mobile-Contrato.git +refs/heads/*:refs/remotes/origin/*" returned status code 128:
stdout: 
stderr: remote: Invalid username or password.
fatal: Authentication failed for 'https://github.com/not-show-my-url.git'

有趣的是,如果我使用 Freestyle 项目,添加 git 存储库,并使用我上面在 Pipeline 项目中使用的相同凭据,我必须克隆该项目,所以我认为身份验证不是问题.

Docker 文件

FROM node

RUN apt-get update && apt-get upgrade -y \
    && apt-get clean

RUN mkdir /app
WORKDIR /app

COPY package*.json /app/

RUN npm install

COPY src /app/src

EXPOSE 3000

CMD [ "npm", "start" ]

詹金斯文件

pipeline {
  agent any
  tools {nodejs "node" }
  stages {
    stage('Cloning Git') {
      steps {
        git 'https://github.com/not-show-my-url.git'
      }
    }
    stage('Build') {
       steps {
         sh 'npm install'
       }
    }
    stage('Test') {
      steps {
        sh 'npm test'
      }
    }
  }
}

凭据确实是问题所在,您需要将凭据 ID 添加到 git 管道步骤中,如下所示:

pipeline {
  agent any
  tools {nodejs "node" }
  stages {
    stage('Cloning Git') {
      steps {
        git url: 'https://github.com/not-show-my-url.git',
            credentialsId: 'your-credentials-id'
      }
    }
    stage('Build') {
       steps {
         sh 'npm install'
       }
    }
    stage('Test') {
      steps {
        sh 'npm test'
      }
    }
  }
}

credentialsId可以从http:///yourjenkinsinstall/credentials.

获取

您必须添加凭据,然后用于配置管道作业: