简体   繁体   English

Jenkins在Docker中触发按需奴隶

[英]Jenkins trigger on-demand slaves in dockers

I'm looking for a way to run Jenkins jobs/build inside Jenkins slaves, dynamically (on-demand) started docker. 我正在寻找一种在Jenkins奴隶内部动态(按需)启动docker来运行Jenkins作业/构建的方法。 Attaching schema for visual understanding. 附加架构以进行视觉理解。 What I'm actually looking for and my flow looks like: 我实际上正在寻找的内容和流程如下所示:

1) Triggering Jenkins job (manually/git/gerrit) 1)触发詹金斯工作(手动/ git / gerrit)
2) Jenkins master (running in docker) starts slave machine docker (and pass script/instructions of the build) 2)Jenkins主服务器(在docker中运行)启动从机docker(并传递构建脚本/指令)
3) Build is running on Jenkins slave (or slaves if parallel/pipeline) 3)Build在Jenkins奴隶上运行(如果是并行/流水线则在奴隶上运行)
4) Result returned to Jenkins master 4)结果返回给詹金斯大师
5) Jenkins slave docker stops 5)詹金斯奴隶码头工人停下来

詹金斯流

Is it possible to do it this way? 有可能这样做吗?

  1. Docker slave image creation steps like installing openssh, user creation, mentioned in the below link. Docker从属映像创建步骤(如安装openssh,用户创建)在下面的链接中提到。 Install docker plugin from the below link. 从下面的链接安装docker插件。

    Click here ! 点击这里

  2. Go to jenkins global configuration, Under cloud headings, docker configuration will be there, enter docker host url with port number, credential not required. 转到jenkins全局配置,在云标题下,将有docker配置,输入带有端口号的docker主机URL,不需要凭据。 give some values for connection timeout & read timeout. 提供一些连接超时和读取超时的值。

  3. Under docker template - Enter the docker image name which we created in the point number 1. 在docker模板下-输入我们在点编号1中创建的docker映像名称。

  4. Set Label number (Give this label name during Jenkins job creation and restrict to this slave name), 设置标签编号(在创建詹金斯作业期间提供此标签名称,并限制为该从属名称),

  5. Select the usage option - > only build job with label restriction. 选择用法选项->仅带有标签限制的构建作业。

  6. No of executor -> minimum 1. Select launch method as ssh, enter the user credential to login, which we created in docker image in the step number 1. 执行程序数量->最小1.选择启动方法为ssh,输入要登录的用户凭证,该凭证是我们在docker映像中的步骤1中创建的。

create a job restrict to docker slave label, run, ondemand it wil spun up container. 创建一个限制于docker slave标签的作业,运行并按需旋转容器。

Use this plugin: https://wiki.jenkins-ci.org/display/JENKINS/Yet+Another+Docker+Plugin 使用此插件: https : //wiki.jenkins-ci.org/display/JENKINS/Yet+Another+Docker+Plugin

After instalation (it requires Java 1.8) naviaget to configuration. 安装完成(需要Java 1.8)后,naviaget进行配置。 There are two steps: 分两个步骤:

  1. configure docker "cloud" 配置泊坞窗“云”
  2. add "instances" (docker images) you want to run the build on 添加要在其上运行构建的“实例”(docker映像)

Every image should have label assigned - use this label in you job configuration to tell Jenkins explicitlyon which node the job should be run 每个图像都应分配标签-在作业配置中使用此标签可以明确告诉Jenkins应在哪个节点上运行作业

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM