在使用作业 DSL 的多个 SCM 的情况下,仅对一个存储库进行更改
Make Changes only to one repository, in case of Multiple SCM using Job DSL
我正在通过复制模板作业在 Jenkins 中创建一个新作业。对于具有单个存储库的模板,我使用以下代码将分支更改为构建部分。
job('example') {
using('template_job')
configure { node ->
node / scm / branches / 'hudson.plugins.git.BranchSpec' {
name 'branchname'
}
}
}
但现在我的模板作业有多个存储库,我必须更改分支以使用 Configure Block 为其中一个存储库构建。我怎样才能做到这一点。
我试过下面的代码,因为 well.Its 不工作,没有做任何更改。对这项工作进行任何修改吗?
configure {node ->
node / scm/ 'hudson.plugins.git.GitSCM'[1] / branches / 'hudson.plugins.git.BranchSpec'{
name branchName1
};
}
/
运算符仅 returns 具有给定名称的第一个 child。您需要将中间节点分配给一个变量,然后使用 groovy.util.Node
API 访问任何 child。从那时起,您可以再次使用 /
进行导航。下面的示例修改了第二个 SCM 配置,索引从零开始。
job('example') {
using('template')
configure { node ->
def scms = node / scm / scms
scms.children()[1] / branches / 'hudson.plugins.git.BranchSpec'{
name('foo')
}
}
}
我正在通过复制模板作业在 Jenkins 中创建一个新作业。对于具有单个存储库的模板,我使用以下代码将分支更改为构建部分。
job('example') {
using('template_job')
configure { node ->
node / scm / branches / 'hudson.plugins.git.BranchSpec' {
name 'branchname'
}
}
}
但现在我的模板作业有多个存储库,我必须更改分支以使用 Configure Block 为其中一个存储库构建。我怎样才能做到这一点。
我试过下面的代码,因为 well.Its 不工作,没有做任何更改。对这项工作进行任何修改吗?
configure {node ->
node / scm/ 'hudson.plugins.git.GitSCM'[1] / branches / 'hudson.plugins.git.BranchSpec'{
name branchName1
};
}
/
运算符仅 returns 具有给定名称的第一个 child。您需要将中间节点分配给一个变量,然后使用 groovy.util.Node
API 访问任何 child。从那时起,您可以再次使用 /
进行导航。下面的示例修改了第二个 SCM 配置,索引从零开始。
job('example') {
using('template')
configure { node ->
def scms = node / scm / scms
scms.children()[1] / branches / 'hudson.plugins.git.BranchSpec'{
name('foo')
}
}
}