如何configurationJenkinsfile来构builddocker镜像并将其推送到私有registry

我有两个问题。 但是,也许我不知道如何为这个问题添加标签,所以我添加了标签。 第一个问题是关于jenkins插件的使用,以烘烤和推动docker形象使用这个 。 下面是我的Jenkinsfile脚本。 我完成了在目标目录中build立jar文件。 然后我想运行这个docker插件来烘焙这件神器。 如你所知,我们需要有一个Dockerfile,所以我把它放在一个git克隆源代码的根目录下。 我如何configuration这个? 我不知道如何做到这一点。 如果我跑下面,jenkins告诉说,没有步骤。

pipeline { agent any stages { stage('build') { steps { git branch: 'master', credentialsId: 'e.joe-gitlab', url: 'http://70.121.224.108/gitlab/cicd/spring-petclinic.git' sh 'mvn clean package' } } stage('verify') { steps { sh 'ls -alF target' } } stage('build-docker-image') { steps { docker.withRegistry('https://sds.redii.net/', 'redii-e.joe') { def app = docker.build("sds.redii.net/e-joe/spring-pet-clinic-demo:v1",'.') app.push() } } } } } 

更新这是另一个Jenkinspipe道语法sniffet生成器。 但它也不工作。

 pipeline { agent any stages { stage('build') { steps { git branch: 'master', credentialsId: 'e.joe-gitlab', url: 'http://70.121.224.108/gitlab/cicd/spring-petclinic.git' sh 'mvn clean package' } } stage('verify') { steps { sh 'ls -alF target' } } stage('docker') { withDockerRegistry([credentialsId: 'redii-e.joe', url: 'https://sds.redii.net']) { def app = docker.build("sds.redii.net/e-joe/spring-pet-clinic-demo:v1",'.') app.push() } } } } 

Dokerfile如下所示。 如果我尝试在我的本地烘焙图像,我得到以下错误。

 container_linux.go:247: starting container process caused "chdir to cwd (\"/usr/myapp\") set in config.json failed: not a directory" oci runtime error: container_linux.go:247: starting container process caused "chdir to cwd (\"/usr/myapp\") set in config.json failed: not a directory" : Are you trying to mount a directory onto a file (or vice-versa)? Check if the specified host path exists and is the expected type 

DockerFile

 FROM openjdk:7 COPY ./target/spring-petclinic-1.5.1.jar /usr/myapp WORKDIR /usr/myapp RUN java spring-petclinic-1.5.1.jar 

您正在将.jar写入/usr/myapp 。 这意味着/usr/myapp将是jar文件而不是目录,导致错误。 更改您的docker复制行COPY ./target/spring-petclinic-1.5.1.jar /usr/myapp/ (与尾部的斜杠)和您的Dockerfile应该工作。