gpt4 book ai didi

远程主机的 Jenkins 任务

转载 作者:行者123 更新时间:2023-12-02 07:03:43 25 4
gpt4 key购买 nike

在部署场景中,我需要在主机列表上创建并运行 jenkins 任务,即创建类似参数化任务(其中 ip 地址是参数)或 Multijob Plugin 上的任务。具有 HOST 轴,但仅由 2 个轴在多个主机上并行运行。

其中一个选项可能是使用主机列表运行 ansible,但我想分别查看每个主机的状态,并在需要时重新启动 jenkins 作业。

主要选项是使用 Job DSL PluginPipeline Plugin ,但在这里我需要帮助来理解应该使用 dsl groovy 代码的哪些类/方法来实现此目的。
有人可以帮忙吗?

最佳答案

假设主机已配置为 Jenkins 从机。假设管道作业参数中提供了主机HOSTS 作为空格分隔的列表。以下示例应该可以帮助您入门:

def hosts_pairs = HOSTS.split().collate(2)

for (pair in host_pairs) {
def branches = [:]
for (h in pair) {
def host = h // fresh variable per iteration; it will be mutated
branches[host] = {
stage(host) {
node(host) {
// do the actual job here, e.g.
// execute a shell script
sh "echo hello world"
}
}
}
}
parallel branches
}

关于远程主机的 Jenkins 任务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39659980/

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