厨师:詹金斯超市食谱自动化工作部署

时间:2017-06-12 13:38:33

标签: jenkins chef bitbucket

我目前正在使用Jenkins supermarket cookbook部署在我的Chef托管节点上作为服务运行的Jenkins实例。到目前为止,我已经修改了我的_master_war_配方文件以安装Jenkins并使用runit启动Jenkins作为服务,安装我需要的所有插件版本以及启用基于矩阵的安全性并创建基本管理员帐户。还应该注意我们使用BitBucket进行源代码控制。

我还希望将我的作业添加为自动Jenkins部署的一部分。据我所知,这样做的方法是将作业配置文件从我的Chef工作站上的目录复制到受管节点上的目录(Chef的缓存路径)。

根据Jenkins public supermarket cookbook自述文件:

  

:create action需要一个Jenkins作业config.xml。这个配置文件   必须存在于目标节点上并包含有效的Jenkins作业   配置文件。因为Jenkins CLI实际上是读取和   生成自己的此文件副本,请勿编写此配置   詹金斯的工作。我们建议将它们放在Chef的文件中   缓存路径。

由于这些作业配置会定期更改,我想知道在我的主厨工作站上维护最新的作业配置文件副本以便部署到我的受管节点的最佳方法是什么?

我是否正确理解了食谱文档,因为我们需要作业配置文件的本地副本(在Chef工作站上),然后将其复制到受管节点上的Chef的缓存文件路径?

提前感谢任何人能够提供的任何帮助。

1 个答案:

答案 0 :(得分:2)

Personally, I count setting up Jenkins jobs a lot more into the domain of Jenkins instead of Chef. The Jenkins community has developed several "jobs as code" approaches, the most popular ones being the Job DSL and the Jenkins Pipelines, with the latter one being the probably better starting point.

What remains up to the Chef cookbook is to define the seed job, either e.g. for the "Bitbucket Organisation Folder" plugin (and the one job that points to your organisation at BitBucket) or a so-called "Seed job" for the Job DSL.

Regarding automated setup of pipelines, I recommend a look at Torben Knerr's examples. This uses

  • Pipeline (as defined in Jenkinsfiles) for the actual build jobs
  • a Job DSL seed job to set up the pipeline job(s)

Regarding the actual implementation in Chef, you can see an example in a cookbook of mine. The template resource copies a file from the cookbook (in the templates/ subdirectory) into some temporary path, from where the jenkins_job resource picks it up (on the Jenkins server).

So I'm not sure, if you got it right regarding:

will need a local copy of the job configuration file (on the Chef workstation)

So you just need it once on your workstation to add it to the cookbook, yes.