jenkinsstream水线代码与docker错误

对于我在GitHub上的一个项目,我想将其作为Docker镜像,并将其推送到Docker中心。 该项目是一个Scala代码库。

这里是我的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仓库中取出。 那么这里有什么问题? 我怎么能做这个工作?

我经历了完全相同的错误。 我的设置:

  • 在dockerized Jenkins(版本2.32.3)
  • 在作业的configuration中,我指定了签出到一个子目录:打开configuration,例如https://myJenkins/job/my-job/configure 。 在底部,请参阅Pipeline – > Additional Behaviours – > Check out into a sub-directory Local subdirectory for repoLocal subdirectory for repo设置Local subdirectory for repo ,例如, my-sub-dir
  • 期望值:在退房时, Jenkinsfile最终在my-sub-dir/Jenkinsfile
  • 通过Script path选项,您可以configurationJenkinsfile的位置,以便Jenkins可以开始构build。 我把my-sub-dir/Jenkinsfile作为价值。

然后我收到你在你的问题上粘贴的exception。 我通过将Script Path设置为Jenkinsfile来修复它。 如果您没有指定检出的子目录,则仍然尝试对“ Script Path双重检查。

注意:我有另一个Jenkins实例在工作。 在那里,我必须指定Script Path包括自定义检出子目录(如上面的期望中所述)。