Jenkins與Docker相關的Plugin使用
Jenkins與Docker相關的Plugin
在Jenkins Plugin頁面搜索與Docker相關的插件,有如下幾個:
-
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.
-
Docker build step plugin — This plugin allows to add various Docker commands into you job as a build step.
-
Docker Plugin — This plugin allows slaves to be dynamically provisioned using Docker.
-
Kubernetes Plugin — This plugin allows slaves to be dynamically provisioned on multiple Docker hosts using Kubernetes.
-
Docker Commons Plugin — APIs for using Docker from other plugins.
其中,它們間的關系如下:
-
Docker commons Plugin為其他與Docker相關的插件提供了APIs
-
CloudBees Docker Build and Publish plugin和Docker build step plugin都依賴了Docker commons Plugin
-
Kubernetes Plugin依賴了Docker Plugin
下面主要介紹下Docker build step plugin和CloudBees Docker Build and Publish plugin的使用。
Docker build step plugin使用
設置Docker URL
系統管理→系統設置→Docker Builder,設置Docker URL並測試連接。
在Jenkins JOB的構建區域,增加構建步驟→Execute Docker container
有一系列Docker Command可選擇
以重啟一個容器為例
選擇Restart containers命令,並填寫Container ID(s):
Jenkins JOB創建成功後,點擊構建,日志輸出如下:
以Push鏡像到Docker registry為例
選擇Push images命令,並填寫相關信息:
Jenkins JOB創建成功後,點擊構建,日志輸出如下:
Docker Build Publish Plugin使用
設置源碼地址,這裡使用的是GIT@OSC
該項目是個Docker化的項目,Dockerfile在根目錄下
在Jenkins JOB的構建區域,增加構建步驟→Docker Build and Publish
此外,Docker Build Publish Plugin還要一些高級選項
Jenkins JOB創建成功後,點擊構建,日志輸出如下