MDa*_*alt 7 groovy gradle jenkins-job-dsl
我正在尝试做一系列本来应该很简单的事情,但却给我带来了很多痛苦。在较高的层次上,我想循环遍历一个数组并将每个值传递到一个 gradle 任务中,该任务应该返回一个自己的数组。然后我想使用这个数组来设置一些 Jenkins 配置。
我尝试了多种方法来实现这项工作,但这是我当前的设置:
project.ext.currentItemEvaluated = "microservice-1"
task getSnapshotDependencies {
def item = currentItemEvaluated
def snapshotDependencies = []
//this does a load of stuff like looping through gradle dependencies,
//which means this really needs to be a gradle task rather than a
//function etc. It eventually populates the snapshotDependencies array.
return snapshotDependencies
}
jenkins {
jobs {
def items = getItems() //returns an array of projects to loop through
items.each { item ->
"${item}-build" {
project.ext.currentItemEvaluated = item
def dependencies = project.getSnapshotDependencies
dsl {
configure configureLog()
//set some config here using the returned dependencies array
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
我无法真正改变詹金斯块的设置方式,因为它已经很成熟,所以如果可能的话,我需要在该结构内工作。
我尝试了多种方法来尝试将变量传递到任务中 - 这里我使用项目变量。问题似乎是任务在詹金斯块之前评估,并且我无法弄清楚如何使用新设置的currentItemEvaluated变量再次正确评估任务。
关于我还可以尝试什么的任何想法?
| 归档时间: |
|
| 查看次数: |
5583 次 |
| 最近记录: |