运行 使用声明式管道在不同存储库上并行执行相同的 Jenkins 作业
Run same Jenkins job on different repositories in parallel using Declarative Pipeline
我的目标是 运行 在多个存储库上并行 check-single-repo
相同的作业。
下面的管道似乎没有达到目标:
pipeline {
agent any
options {
ansiColor('xterm')
}
parameters {
extendedChoice description: '', multiSelectDelimiter: ',', name: 'REPO_NAMES', quoteValue: false, saveJSONParameterToFile: false, type: 'PT_CHECKBOX', value: 'repo1,repo2,repo3', visibleItemCount: 3
}
stages {
stage('Prepare repos to run on') {
steps {
script {
repo_names = params.REPO_NAMES.split(',')
def single_repo_jobs = [:]
for (repo_name in repo_names) {
println repo_name
single_repo_jobs[repo_name] = {
stage(repo_name) {
catchError {
build job: 'check-single-repo',
parameters:
[
string(name:'REPO_NAME', value: repo_name)
] }
}
}
}
println single_repo_jobs
parallel single_repo_jobs
}
}
}
}
}
其输出:
...
repo1
repo2
repo3
{repo1=org.jenkinsci.plugins.workflow.cps.CpsClosure2@3a396959, repo2=org.jenkinsci.plugins.workflow.cps.CpsClosure2@1a4b5000, repo3=org.jenkinsci.plugins.workflow.cps.CpsClosure2@1d034ac}
[Pipeline] parallel
[Pipeline] { (Branch: repo1)
[Pipeline] { (Branch: repo2)
[Pipeline] { (Branch: repo3)
[Pipeline] stage
[Pipeline] { (repo3)
[Pipeline] stage
[Pipeline] { (repo3)
[Pipeline] stage
[Pipeline] { (repo3)
[Pipeline] catchError
[Pipeline] {
[Pipeline] catchError
[Pipeline] {
[Pipeline] catchError
[Pipeline] {
[Pipeline] build (Building check-single-repo)
Scheduling project: check-single-repo
[Pipeline] build (Building check-single-repo)
Scheduling project: check-single-repo
[Pipeline] build (Building check-single-repo)
Scheduling project: check-single-repo
Starting building: check-single-repo #230
Starting building: check-single-repo #230
Starting building: check-single-repo #230
[Pipeline] }
check-single-repo #230 repo3 completed with status UNSTABLE (propagate: false to ignore)
[Pipeline] }
check-single-repo #230 repo3 completed with status UNSTABLE (propagate: false to ignore)
[Pipeline] }
check-single-repo #230 repo3 completed with status UNSTABLE (propagate: false to ignore)
...
因为它在 repo3
上仅调用一个管道 #230
如何使用声明式管道运行在不同存储库上并行执行相同的 Jenkins 作业?
在遵循 example from docs:
之后,以下代码对我有用
pipeline {
agent any
options {
ansiColor('xterm')
}
parameters {
extendedChoice description: '', multiSelectDelimiter: ',', name: 'REPO_NAMES', quoteValue: false, saveJSONParameterToFile: false, type: 'PT_CHECKBOX', value: 'repo1,repo2,repo3', visibleItemCount: 3
}
stages {
stage('Prepare repos to run on') {
steps {
script {
def repo_names = params.REPO_NAMES.split(',')
def single_repo_jobs = repo_names.collectEntries {
["${it}" :
{
catchError {
stage(it) {
build job: 'check-single-repo',
parameters:
[
string(name:'REPO_NAME', value: "${it}")
]
}
}
}
]
}
parallel single_repo_jobs
}
}
}
}
}
我的目标是 运行 在多个存储库上并行 check-single-repo
相同的作业。
下面的管道似乎没有达到目标:
pipeline {
agent any
options {
ansiColor('xterm')
}
parameters {
extendedChoice description: '', multiSelectDelimiter: ',', name: 'REPO_NAMES', quoteValue: false, saveJSONParameterToFile: false, type: 'PT_CHECKBOX', value: 'repo1,repo2,repo3', visibleItemCount: 3
}
stages {
stage('Prepare repos to run on') {
steps {
script {
repo_names = params.REPO_NAMES.split(',')
def single_repo_jobs = [:]
for (repo_name in repo_names) {
println repo_name
single_repo_jobs[repo_name] = {
stage(repo_name) {
catchError {
build job: 'check-single-repo',
parameters:
[
string(name:'REPO_NAME', value: repo_name)
] }
}
}
}
println single_repo_jobs
parallel single_repo_jobs
}
}
}
}
}
其输出:
...
repo1
repo2
repo3
{repo1=org.jenkinsci.plugins.workflow.cps.CpsClosure2@3a396959, repo2=org.jenkinsci.plugins.workflow.cps.CpsClosure2@1a4b5000, repo3=org.jenkinsci.plugins.workflow.cps.CpsClosure2@1d034ac}
[Pipeline] parallel
[Pipeline] { (Branch: repo1)
[Pipeline] { (Branch: repo2)
[Pipeline] { (Branch: repo3)
[Pipeline] stage
[Pipeline] { (repo3)
[Pipeline] stage
[Pipeline] { (repo3)
[Pipeline] stage
[Pipeline] { (repo3)
[Pipeline] catchError
[Pipeline] {
[Pipeline] catchError
[Pipeline] {
[Pipeline] catchError
[Pipeline] {
[Pipeline] build (Building check-single-repo)
Scheduling project: check-single-repo
[Pipeline] build (Building check-single-repo)
Scheduling project: check-single-repo
[Pipeline] build (Building check-single-repo)
Scheduling project: check-single-repo
Starting building: check-single-repo #230
Starting building: check-single-repo #230
Starting building: check-single-repo #230
[Pipeline] }
check-single-repo #230 repo3 completed with status UNSTABLE (propagate: false to ignore)
[Pipeline] }
check-single-repo #230 repo3 completed with status UNSTABLE (propagate: false to ignore)
[Pipeline] }
check-single-repo #230 repo3 completed with status UNSTABLE (propagate: false to ignore)
...
因为它在 repo3
#230
如何使用声明式管道运行在不同存储库上并行执行相同的 Jenkins 作业?
在遵循 example from docs:
之后,以下代码对我有用pipeline {
agent any
options {
ansiColor('xterm')
}
parameters {
extendedChoice description: '', multiSelectDelimiter: ',', name: 'REPO_NAMES', quoteValue: false, saveJSONParameterToFile: false, type: 'PT_CHECKBOX', value: 'repo1,repo2,repo3', visibleItemCount: 3
}
stages {
stage('Prepare repos to run on') {
steps {
script {
def repo_names = params.REPO_NAMES.split(',')
def single_repo_jobs = repo_names.collectEntries {
["${it}" :
{
catchError {
stage(it) {
build job: 'check-single-repo',
parameters:
[
string(name:'REPO_NAME', value: "${it}")
]
}
}
}
]
}
parallel single_repo_jobs
}
}
}
}
}