配置Jenkins在构建时根据构建参数以编程方式确定从属? [英] Configuring Jenkins to programmatically determine slave at build time from build parameter?

查看:111
本文介绍了配置Jenkins在构建时根据构建参数以编程方式确定从属?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这可能是一个有点不寻常的Jenkins查询,但是我们有一个跨很多项目的项目.它们都是基于Linux的,但是它们跨越了多种体系结构(MIPS,SPARC,ARMv6,ARMv7).

This is perhaps a slightly unusual Jenkins query, but we've got a project that spans many projects. All of them are Linux based, but they span multiple architectures (MIPS, SPARC, ARMv6, ARMv7).

对于一个特定的组件,我们称其为视频编码器",因此,我们将有4个项目:mips-video-encoder,sparc-video-encoder等.

For a specific component, let's call it 'video-encoder', we'll therefore have 4 projects: mips-video-encoder, sparc-video-encoder, etc.

每个项目都建立在4个独立的从站上,并带有与其架构相关的标签,即MIPS从站的标签为'mips''linux'.

Each project is built on 4 separate slaves with a label that correlates to their architecture, i.e. the MIPS slave has the labels 'mips' 'linux'.

我的目标是:

  1. 巩固我们所有单独的工作.这样一来,我们就可以更轻松地修改作业属性,也可以轻松添加更多作业,而不必费力地添加如此多的特定于架构的作业.
  2. 如果我们愿意,一次只能构建一个体系结构.如果MIPS作业失败,我们只想为MIPS而不是其他人构建.

我看过多配置"类型的作业-目前,我们仅使用简单的单一配置作业.我不确定多配置"类型是否允许我们一次仅构建单个体系结构.我玩过配置矩阵,但是不确定是否可以更改/修改它以仅构建 single 平台.看来我可以使用Groovy语句来做到这一点?像这样:

I have looked at the 'Multi-configuration' type job -- at the moment we are just using Single confguration jobs which are simple. I am not sure if the Multi-configuration type allows for us to build only individual architectures at once. I had a play with the configuration matrix, but wasn't sure if this could be changed / adapted to just build a for single platform. It looks like I may be able to use a Groovy statement to do this? Something like:

(label=="mips".implies("slave"=="mips")

也许可以简化为诸如slave == label之类的东西,其中label是作业处于单一配置状态时的前一个名称,现在是一个构建参数?

Maybe that could be simplified to something like slave == label where label is the former name of the job when it was in its single-configuration state and is now a build parameter?

我认为,如果我们可以以编程方式为此选择从服务器,则我们不需要多配置作业.

I am thinking that we don't need a Multi-config job for this, if we can programatically choose the slave for this.

我将非常感谢您提供一些建议,这些建议可以如何合并已有的作业数量,并根据项目的体系结构(作为构建参数)以编程方式更改目标从站.

I would greatly appreciate some advice on how we can consolidate the number of jobs we have and programatically change the target slave based on the architecture of the project which is a build parameter.

在此先感谢

推荐答案

您可以使用系统常规脚本进行包装工作.您需要为此使用groovy插件.让我们称之为包装器作业-video-encoder-wrapper,这是如何配置它的项目符号:

You can make a wrapper job with a system groovy script. You need the groovy plugin for this. let call the wrapper job - video-encoder-wrapper, here are the bullets how to configure it:

  • 定义参数ARCH
  • 通过Execute system Groovy script

import hudson.model.*
encoder=Hudson.instance.getItem('video-encoder')
def arch =build.buildVariableResolver.resolve("ARCH")
label= Hudson.instance.getLabel(arch)
encoder.setAssignedLabel(label)

  • 调用非阻塞下游项目video-encoder,不要忘记传递ARCH参数

  • Invoke non blocking downstream project video-encoder, don't forget to pass the ARCH parameter

    希望有帮助

    这篇关于配置Jenkins在构建时根据构建参数以编程方式确定从属?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆