白雪皇后 發表於 2023-5-31 00:00:00

Jenkins与Docker相关的Plugin使用

<p>在Jenkins Plugin页面搜索与Docker相关的插件,有如下几个:</p>
<ul>
<li>CloudBees Docker Build and Publish plugin — This plugin provides the ability to build projects with a Dockerfile, and publish the resultant tagged image (repo) to the docker registry.</li>
<li>Docker build step plugin — This plugin allows to add various Docker commands into you job as a build step.</li>
<li>Docker Plugin — This plugin allows slaves to be dynamically provisioned using Docker.</li>
<li>Kubernetes Plugin — This plugin allows slaves to be dynamically provisioned on multiple Docker hosts using Kubernetes.</li>
<li>Docker Commons Plugin — APIs for using Docker from other plugins.</li>
</ul>
<p>其中,它们间的关系如下:</p>
<ul>
<li>Docker commons Plugin为其他与Docker相关的插件提供了APIs</li>
<li>CloudBees Docker Build and Publish plugin和Docker build step plugin都依赖了Docker commons Plugin</li>
<li>Kubernetes Plugin依赖了Docker Plugin</li>
</ul>
<p>下面主要介绍下Docker build step plugin和CloudBees Docker Build and Publish plugin的使用。</p>
<h3 id="h3_2">Docker build step plugin使用</h3>
<h4 id="h4_3">设置Docker URL</h4>
<p>系统管理→系统设置→Docker Builder,设置Docker URL并测试连接。</p>
<p><img src="https://zhuji.jb51.net/uploads/img/20230517/87c64e46d912d5f15fd4e7f9afc527b6.jpg" width="630" height="173"></p>
<h4 id="h4_4">在Jenkins JOB的构建区域,增加构建步骤→Execute Docker container</h4>
<p>有一系列Docker Command可选择</p>
<p><img src="https://zhuji.jb51.net/uploads/img/20230517/d680d48fb823730dc4643d5fd2861e39.jpg" width="360" height="205"></p>
<p><img src="https://zhuji.jb51.net/uploads/img/20230517/af2ff54a219d2264b694e8d25d334510.jpg" width="478" height="366"></p>
<h4 id="h4_5">以重启一个容器为例</h4>
<p>选择Restart containers命令,并填写Container ID(s):</p>
<p><img src="https://zhuji.jb51.net/uploads/img/20230517/80e82aa7b914c76c0443b42e9b5cc79f.jpg" width="587" height="230"></p>
<p>Jenkins JOB创建成功后,点击构建,日志输出如下:</p>
<p><img src="https://zhuji.jb51.net/uploads/img/20230517/9f13e781c870ad142ed3cca78257c844.jpg" width="471" height="155"></p>
<h4 id="h4_6">以Push镜像到Docker registry为例</h4>
<p>选择Push images命令,并填写相关信息:</p>
<p><img src="https://zhuji.jb51.net/uploads/img/20230517/49ea9b064c322a86e7c01426605ddbf7.jpg" width="629" height="349"></p>
<p>Jenkins JOB创建成功后,点击构建,日志输出如下:</p>
<p><img src="https://zhuji.jb51.net/uploads/img/20230517/15c8411604ed83d0afd2d70c0c9bb6b5.jpg" width="927" height="389"></p>
<h3 id="h3_7">Docker Build Publish Plugin使用</h3>
<h4 id="h4_8">设置源码地址,这里使用的是GIT@OSC</h4>
<p>该项目是个Docker化的项目,Dockerfile在根目录下</p>
<p><img src="https://zhuji.jb51.net/uploads/img/20230517/44dfa1c64066d7b3d493f8ac1da72538.jpg" width="622" height="299"></p>
<h4 id="h4_9">在Jenkins JOB的构建区域,增加构建步骤→Docker Build and Publish</h4>
<p><img src="https://zhuji.jb51.net/uploads/img/20230517/8ef3b36708daf6504d3cdc2084950d49.jpg" width="728" height="427"></p>
<p>此外,Docker Build Publish Plugin还要一些高级选项</p>
<p><img src="https://zhuji.jb51.net/uploads/img/20230517/b40d70e4ef04de8eb5aa21f1f212d034.jpg" width="742" height="364"></p>
<h4 id="h4_10">Jenkins JOB创建成功后,点击构建,日志输出如下</h4>
<p><img src="https://zhuji.jb51.net/uploads/img/20230517/7966605a6b8a870847fc696c9a51c401.jpg" width="632" height="1024"></p>
頁: [1]
查看完整版本: Jenkins与Docker相关的Plugin使用