Jenkins Job DSL:未知 return 语句
Jenkins Job DSL: unknown return statement
几天前,我遇到了一段用于覆盖 Jenkins 插件默认配置的代码片段“GitHub SCM Source”(未知作者):
Closure configOverride(String repo, int id, String cred) {
return {
it / sources / 'data' / 'jenkins.branch.BranchSource' << {
source(class: 'org.jenkinsci.plugins.github_branch_source.GitHubSCMSource') {
id(id)
scanCredentialsId(cred)
checkoutCredentialsId('SAME')
repoOwner('owner')
repository(repo)
includes('*')
buildOriginBranch('true')
buildOriginBranchWithPR('true')
buildOriginPRMerge('false')
buildOriginPRHead('false')
buildForkPRMerge('true')
buildForkPRHead('false')
}
}
}
}
一切都很好,除了我无法理解以下行:
it / sources / 'data' / 'jenkins.branch.BranchSource' << { ... }
我试图找到一些关于在 groovy 中使用“/”的解释,但没有成功。可能我不知道具体要搜索什么。
有人可以帮我 link 文档或简短的解释。
这是 超载
运算符
Groovy allows you to overload the various operators so that they can be used with your own classes. Consider this simple class:
class Bucket {
int size
Bucket(int size) { this.size = size }
Bucket plus(Bucket other) {
return new Bucket(this.size + other.size)
}
}
Just by implementing the plus() method, the Bucket class can now be used with the + operator like so:
def b1 = new Bucket(4)
def b2 = new Bucket(11)
assert (b1 + b2).size == 15
对于 /
将覆盖 T div(T x)
此代码片段在 Jenkins DSL 中用于“multibranchPipelineJob”。闭包 configOverride 用于生成一个 XML 对象,该对象替换以下路径“sources/data/jenkins.branch.BranchSource”.
中 config.xml 中的默认配置
几天前,我遇到了一段用于覆盖 Jenkins 插件默认配置的代码片段“GitHub SCM Source”(未知作者):
Closure configOverride(String repo, int id, String cred) {
return {
it / sources / 'data' / 'jenkins.branch.BranchSource' << {
source(class: 'org.jenkinsci.plugins.github_branch_source.GitHubSCMSource') {
id(id)
scanCredentialsId(cred)
checkoutCredentialsId('SAME')
repoOwner('owner')
repository(repo)
includes('*')
buildOriginBranch('true')
buildOriginBranchWithPR('true')
buildOriginPRMerge('false')
buildOriginPRHead('false')
buildForkPRMerge('true')
buildForkPRHead('false')
}
}
}
}
一切都很好,除了我无法理解以下行:
it / sources / 'data' / 'jenkins.branch.BranchSource' << { ... }
我试图找到一些关于在 groovy 中使用“/”的解释,但没有成功。可能我不知道具体要搜索什么。
有人可以帮我 link 文档或简短的解释。
这是 超载 运算符
Groovy allows you to overload the various operators so that they can be used with your own classes. Consider this simple class:
class Bucket { int size Bucket(int size) { this.size = size } Bucket plus(Bucket other) { return new Bucket(this.size + other.size) } }
Just by implementing the plus() method, the Bucket class can now be used with the + operator like so:
def b1 = new Bucket(4) def b2 = new Bucket(11) assert (b1 + b2).size == 15
对于 /
将覆盖 T div(T x)
此代码片段在 Jenkins DSL 中用于“multibranchPipelineJob”。闭包 configOverride 用于生成一个 XML 对象,该对象替换以下路径“sources/data/jenkins.branch.BranchSource”.
中 config.xml 中的默认配置