Jenkins管道为代码,但出现Docker错误

spa*_*rkr 2 jenkins docker jenkins-pipeline

对于我在GitHub上的一个项目,我想将其构建为docker映像并将其推送到我的docker hub。该项目是一个具有Scala代码库的sbt项目。

这是我的JenkinsFile的定义方式:

#!groovy

node {
  // set this in Jenkins server under Manage Jenkins > Credentials > System > Global Credentials
  docker.withRegistry('https://hub.docker.com/', 'joesan-docker-hub-credentials') {
    git credentialsId: '630bd271-01e7-48c3-bc5f-5df059c1abb8', url: 'https://github.com/joesan/monix-samples.git'

    sh "git rev-parse HEAD > .git/commit-id"
    def commit_id = readFile('.git/commit-id').trim()
    println comit_id

    stage "build" {
      def app = docker.build "Monix-Sample"
    }

    stage "publish" {
      app.push 'master'
      app.push "${commit_id}"
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

当我尝试从我的Jenkins服务器运行此文件时,出现以下错误:

java.io.FileNotFoundException
    at jenkins.plugins.git.GitSCMFile$3.invoke(GitSCMFile.java:167)
    at jenkins.plugins.git.GitSCMFile$3.invoke(GitSCMFile.java:159)
    at jenkins.plugins.git.GitSCMFileSystem$3.invoke(GitSCMFileSystem.java:161)
    at org.jenkinsci.plugins.gitclient.AbstractGitAPIImpl.withRepository(AbstractGitAPIImpl.java:29)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.withRepository(CliGitAPIImpl.java:65)
    at jenkins.plugins.git.GitSCMFileSystem.invoke(GitSCMFileSystem.java:157)
    at jenkins.plugins.git.GitSCMFile.content(GitSCMFile.java:159)
    at jenkins.scm.api.SCMFile.contentAsString(SCMFile.java:338)
    at org.jenkinsci.plugins.workflow.cps.CpsScmFlowDefinition.create(CpsScmFlowDefinition.java:101)
    at org.jenkinsci.plugins.workflow.cps.CpsScmFlowDefinition.create(CpsScmFlowDefinition.java:59)
    at org.jenkinsci.plugins.workflow.job.WorkflowRun.run(WorkflowRun.java:232)
    at hudson.model.ResourceController.execute(ResourceController.java:98)
    at hudson.model.Executor.run(Executor.java:404)
Finished: FAILURE
Run Code Online (Sandbox Code Playgroud)

由于这是在Azure上的VM内运行的,因此我认为VM无法到达外部,但事实并非如此,因为我能够通过SSH进入VM并从Git存储库中进行git pull了。那么这是什么问题呢?我该如何进行这项工作?

小智 5

对我来说,取消选中“轻量级结帐”可解决此问题