gpt4 book ai didi

groovy - Jenkins 脚本限制给定节点的所有构建

转载 作者:行者123 更新时间:2023-12-02 08:55:33 24 4
gpt4 key购买 nike

我们最近在 Jenkins 构建环境中添加了第二个从属节点,运行不同的操作系统(Linux 而不是 Windows)以进行特定构建。毫不奇怪,这意味着我们需要通过“限制此项目可以运行的位置”设置来限制构建。然而,我们有很多构建(100 多个),因此点击所有构建来手动更改此设置的前景并不令我兴奋。

有人可以提供一个常规脚本来通过 Jenkins 脚本控制台实现此目的吗?我过去曾使用类似的脚本来更改其他设置,但我找不到此特定设置的任何引用。

最佳答案

根据以前的脚本和 Jenkins 源代码,我自己设法找出了脚本。脚本如下:

import hudson.model.*
import hudson.model.labels.*
import hudson.maven.*
import hudson.tasks.*
import hudson.plugins.git.*

hudsonInstance = hudson.model.Hudson.instance
allItems = hudsonInstance.allItems
buildableItems = allItems.findAll{ job -> job instanceof BuildableItemWithBuildWrappers }

buildableItems.each { item ->
boolean shouldSave = false
item.allJobs.each { job ->
job.assignedLabel = new LabelAtom('windows-x86')
}
}

将“windows-x86”替换为您需要的节点标签。如有必要,您还可以根据 item.name 进行条件更改以过滤掉某些作业。

关于groovy - Jenkins 脚本限制给定节点的所有构建,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29117751/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com