docker - Jenkins 管道即代码,出现 Docker 错误

标签 docker jenkins 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}"
    }
  }
}

当我尝试从 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

由于这是在 Azure 上的虚拟机内运行,我认为虚拟机无法访问外部,但事实似乎并非如此,因为我能够 ssh 进入虚拟机并从 Git 存储库中进行 git pull。那么这里有什么问题呢?我怎样才能做到这一点?

最佳答案

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

关于docker - Jenkins 管道即代码,出现 Docker 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43078203/

相关文章:

docker 容器处于事件状态但未显示端口

jenkins - 如何从 jenkins 变量创建小写变量

Jenkins 文件 : Run a task in all Agents with same label

docker - docker 上的 Grafana : not able to find log

docker - 当 `docker exec`命令在已经运行的容器上运行时,是否可以设置默认命令?

具有构建输出且无源的 Docker 容器

jenkins - 无法让 Jenkins 使用构建状态更新 GitHub Pull 请求

jenkins - 将 Jenkins 管道阶段显示为失败,但不会导致整个作业失败

jenkins - 使用从另一个 Groovy 文件加载的枚举(Jenkins 管道问题)

django - 重新启动 Nginx 或在证书更改时重新加载证书缓存