詹金斯参数化矩阵作业 [英] Jenkins parameterized matrix job

查看:157
本文介绍了詹金斯参数化矩阵作业的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在设置Jenkins作业,以对某些c ++代码运行一堆测试.该代码是在一项詹金斯工作期间生成的.有许多子项目,它们的代码在自己的文件夹中.

I am in the process of setting up a Jenkins job to run a bunch of tests on some c++ code. The code is generated during one Jenkins job. There are a number of sub-projects, with their code in their own folders.

我的想法是有一个矩阵作业,其中每个配置都在一个代码文件文件夹上运行测试.我不确定有两件事是最好的方法...

My thought is to have a matrix job where each configuration runs the test on one folder of code files. There are two things that I am not sure the best way to do though...

  1. 如果要添加更多子文件夹,我想将矩阵作业设置为自动拾取.诸如将文件夹列表作为参数传递给作业,并将该参数用作作业的轴之类的东西.

  1. I would like to set up the matrix job to automatically pick up if more sub-folders are added. Something like passing a list of folders to the job as a parameter, and have that parameter used as the axis for the job.

我希望不要在特定文件夹上运行测试,除非该文件夹中的某些代码被父作业更改.

I would like the test to not be run on a specific folder unless some of the code in that folder was changed by the parent job.

现在,如何设置此测试已完全开放-我正在寻找想法.如果您曾经设置过这样的东西-您是怎么做到的?

Right now how to set up this test is completely open- I am trolling for ideas. If you have ever set up something like this- how did you do it?

推荐答案

我有类似的任务-运行以可变数量的文件夹作为一个轴的矩阵作业.文件夹处于版本控制中,但很容易成为工件.我要做的是创建两个作业,一个是主作业,另一个是普通作业,另一个是从属作业和矩阵.这是需要在主要工作中以常规方式运行的代码:

I had similar task - running a matrix job with variable number of folders as one axis. The folders were in version control but could easily be artifact. What I've done, is create two jobs, one main and normal, the other slave and matrix. Here is the code that needs to be run as elevated groovy in the main job:

import hudson.model.*
def currentBuild = Thread.currentThread().executable;
def jobName = 'SlaveMatrixJob' // Name of the matrix job to configure
def axisFolders = []
def strings =""

// Get the matrix job
def job = hudson.model.Hudson.instance.getItem(jobName)
assert job != null, "The job $jobName could not be found"

// Check it is a matrix job
assert job.getClass() == hudson.matrix.MatrixProject.class, "The job $jobName is of class '${job.getClass().name}', but expecting 'hudson.matrix.MatrixProject'"

// Get the folders
new File("C:\\Path\\Path").eachDirMatch ~/_test.*/, {it ->
   println "Got folder: ${it.name}"
   axisFolders << it.name
}

// Check if the array is empty
assert !axisFolders.isEmpty(), "No folders found to set in the matrix, aborting"

//Sort them
axisFolders.sort()

// Now set new axis list for test folders
def newAxisList = new hudson.matrix.AxisList()
newAxisList.add(new hudson.matrix.TextAxis('TEST_FOLDERS', axisFolders))
job.setAxes(newAxisList)
println "Matrix Job $jobName new axis list: ${job.getAxes().toString()}"

这基本上是从 _test 开始在c:\ path \ path中获得所有折叠,然后将其插入名为 TEST_FOLDERS SlaveMatrixJob 的参数中/strong>.

What this does basically is get all the folde in c:\path\path starting with _test and then inserting them in the SlaveMatrixJob parameter named TEST_FOLDERS.

我不得不完成两项工作,因为在没有安装其他插件的情况下无法进行此动态更新,这在当时是不可能的.

I had to go with two jobs, since I was not able to make this dynamic update work without installing additional plugins, which was not possible at the time.

第二点,您可以向脚本添加逻辑,以检查自上次构建以来文件夹是否已更新,并跳过未更新的文件夹.或者,您可以搜索一些插件,但是我的建议是使用脚本来完成更简单的任务.

For the second point, you could add logic to the script to check if the folders have been updated since the last build and skip the ones that weren't. Or you could search for some plugins, but my advice is go with the script for simpler tasks.

这篇关于詹金斯参数化矩阵作业的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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