如何使用Jenkins从停靠文件构建映像

brvekthn  于 2023-03-17  发布在  Jenkins
关注(0)|答案(2)|浏览(139)

我有下面的脚本,如何从克隆的存储库中的Dockerfile归档创建映像?
我打给Jenkins了

"pipeline"{
   "agent any
triggers"{
      "pollSCM(""* * * * *"")"
   }"stages"{
      "stage(""Checkout"")"{
         "steps"{
            "git url":"https://github.com/example.git",
            "branch":"main"
         }
      }"stage(""Building image"")"{
         "steps"{
           //build the image that is inside the cloned repo
         }
      }
   }"post"{
      "always"{
         "mail to":"example@gmail.com",
         "subject":"Completed Pipeline: ${currentBuild.fullDisplayName}",
         "body":"Your build completed, please check: ${env.BUILD_URL}"
      }
   }
}
rvpgvaaj

rvpgvaaj1#

您必须在代理上安装docker(或podman),并在Dockerfile所在的文件夹中运行docker build
有关更多选项和示例,请阅读docker command reference

7uzetpgm

7uzetpgm2#

您可以使用Docker Pipeline plugin
假设您的存储库根目录中有Dockerfile:

stage('Build and push docker image') {
  steps {
    script {
      def dockerImage = docker.build(dockerImageName)
      
      docker.withRegistry("http://${params.DOCKER_REGISTRY}", 'registry-credentials') {
        dockerImage.push()
      }
    }
  }
}

不确定“Dockerfile archive”到底是什么。如果你需要解压缩一些东西,有Pipeline Utility Steps plugin - unzip

相关问题