今天介绍一个插件 throttle-concurrent-builds-plugin
https://github.com/jenkinsci/throttle-concurrent-builds-plugin
This plugin allows for throttling the number of concurrent builds of a project running per node or globally.
throttle 有节流的意思,也就是限制 某个任务同时并发的个数的。下面分别的讲解 这个插件在 free style project、matrix project 等项目中的应用和异同。
先介绍 自由风格项目 中的用法。
稍后补充
然后介绍 多配置项目 中的用法。
下面截图是配置的一个简单的 多配置项目, 定义了一个坐标,坐标名是 x, x可以使用的值是 1, 2 两个值。
源码分析
通过在 ThrottleQueueTaskDispatcher.java 类 中canRun() 方法打上断点,发现,父任务执行时候会调用一次,而且仅有这一次。子任务在执行的时候会被调用两次。为什么会这样呢? 通过 Queue.java 类中的maintain() 方法可以发现答案的。父任务比较特殊,是没有buildables的,执行的时候也不会占用 执行器。 子任务 第一次调用是 和 父任务一样的位置, 第二次调用 for (BuildableItem p : new ArrayList<>(buildables)) 遍历 buildables的时候。
public CauseOfBlockage canRun(Queue.Item item) hudson.matrix.MatrixProject@6f806be4[test_matrix] 这个是父任务
canRun:90, ThrottleQueueTaskDispatcher
getCauseOfBlockageForItem:1210, Queue
maintain:1572, Queue
public CauseOfBlockage canRun(Queue.Item item) hudson.matrix.MatrixConfiguration@4e2f16c4[test_matrix/x=1] 这个是其中的一个子任务,x=1的情况
canRun:90, ThrottleQueueTaskDispatcher
getCauseOfBlockageForItem:1210, Queue
maintain:1572, Queue
public CauseOfBlockage canRun(Queue.Item item) hudson.matrix.MatrixConfiguration@4e2f16c4[test_matrix/x=1]这个是其中的一个子任务,x=1的情况
canRun:90, ThrottleQueueTaskDispatcher
getCauseOfBlockageForItem:1210, Queue
maintain:1608, Queue for (BuildableItem p : new ArrayList<>(buildables))
public CauseOfBlockage canRun(Queue.Item item) hudson.matrix.MatrixConfiguration@6e1a5a11[test_matrix/x=2]这个是其中的一个子任务,x=2的情况
canRun:90, ThrottleQueueTaskDispatcher
getCauseOfBlockageForItem:1210, Queue
maintain:1572, Queue
public CauseOfBlockage canRun(Queue.Item item) hudson.matrix.MatrixConfiguration@6e1a5a11[test_matrix/x=2]这个是其中的一个子任务,x=2的情况
canRun:90, ThrottleQueueTaskDispatcher
getCauseOfBlockageForItem:1210, Queue
maintain:1608, Queue for (BuildableItem p : new ArrayList<>(buildables))
来源:oschina
链接:https://my.oschina.net/u/4262079/blog/4520505