怎么样新建一个网站,海珠网站建设方案,成都工装装修设计公司,网站添加cmsLockable Resources插件实现资源锁定前言安装插件使用插件资源配置Pipeline中使用前言
用来阻止多个构建在同一时间试图使用同一个资源。这里的资源可能是一个节点、一个代理节点、一组节点或代理节点的集合#xff0c;或者仅仅是一个用于上锁的名字。如果指定的资源没有在全…
Lockable Resources插件实现资源锁定前言安装插件使用插件资源配置Pipeline中使用前言
用来阻止多个构建在同一时间试图使用同一个资源。这里的资源可能是一个节点、一个代理节点、一组节点或代理节点的集合或者仅仅是一个用于上锁的名字。如果指定的资源没有在全局配置中定义那么它将会被自动地添加到系统中。
安装插件
Manage Jenkins -- Mangage Plugins -- 可选插件 -- 输出框输入 Lockable Resources
使用插件
资源配置
Manage jenkins -- System configuration -- 找到Lockable Resources Manager 参数说明 Name 资源的名称,只有定义的名称创建项目的时候才可以使用它,比如printers定义了一个名叫作printers类型的lockable资源Description描述可以添加对资源的描述信息Labels要选择的节点,多个之间用空格分割.比如printer1 printer2 printer3Reserved by被某个对象预留,这里可以填写任意名称,如果有值,则资源不可用,此选项用于对资源的维护 Pipeline中使用
lock(inversePrecedence: true, label: printer1, quantity: 1, variable: resource_name)参数说明 label在全局设置中定义的要锁定的资源的标签quantity在全局设置中定义的具有指定标签的资源被锁定的数量。可以把这个理解成“我必须拥有多少这种资源才能继续前行” 如果你指定了标签但没有指定数量那么标记该标签的所有资源都会被锁定也就是空值或0表示锁定所有匹配的资源variable获取资源名称inversePrecedence表示是否可以后来居上后进先出如果这个参数被设置为true那么最新的构建优先获得资源资源可用时。否则所有构建将按照申请资源的顺序依次获得资源 stage 中使用
新建两个Pipeline – pipeline-lock
pipeline {agent anystages {stage(Lock resource) {steps {script {lock(label: printer1,quantity: 1 ,variable: resource_name) {echo Locked resource name is ${env.resource_name}sleep 30}}sh echo hello world!}}}
}新建两个Pipeline – pipeline-lock-block
pipeline {agent anystages {stage(Lock resource) {steps {script {lock(label: printer1,quantity: 1 ,variable: resource_name) {echo Locked resource name is ${env.resource_name}}}sh echo hello world!}}}
}先运行pipeline-lock再运行 pipeline-lock-block下图为日志输出 option中使用pipeline-lock
pipeline {agent anyoptions {lock(inversePrecedence: true, label: printer1, quantity: 1, variable: resource_name)}stages {stage(Lock resource) {steps {script {echo Locked resource name is ${env.resource_name}sleep 30}sh echo hello world!}}}
}pipeline-lock-block
pipeline {agent anyoptions {lock(inversePrecedence: true, label: printer1, quantity: 1, variable: resource_name)}stages {stage(Lock resource) {steps {script {echo Locked resource name is ${env.resource_name}}sh echo hello world!}}}
}
日志输出