如何在Jenkins中将工件推入Docker镜像

我如何使用docker指令创build工件的docker图像。 我正在使用jenkins工作中的“在docker集装箱内build造”。 这是dockerfile中的指令:

install openjdk 8`RUN apt-get update && \ apt-get install -y openjdk-8-jdk && \ apt-get install -y ant && \ apt-get clean;` 

然后我需要控制Jenkins的工作来执行构build过程。 所以在jenkins Job的Build过程中,执行“Execute Shell”命令并创build工件。 它有一些后期构build操作来运行junittesting用例并运行覆盖报告。 最后,我需要dockerfile来运行指令来创build工件的图像。 添加sourcefile目标文件请build议如何编写docker指令将控制权交给jenkins作业,并在构build过程完成后得到控制权。

您可以使用dockerpipe道插件来执行此操作(请参阅docker对象)

 node("docker") { docker.withRegistry('<<your-docker-registry>>', '<<your-docker-registry-credentials-id>>') { git url: "<<your-git-repo-url>>", credentialsId: '<<your-git-credentials-id>>' sh "git rev-parse HEAD > .git/commit-id" def commit_id = readFile('.git/commit-id').trim() println commit_id def app; stage("build") { app = docker.build "your-project-name" } stage("publish") { app.push 'master' app.push "${commit_id}" } } }