当参数匹配时,我使用管道脚本并行构建作业,但对于每个参数,它最多并行构建10到15个作业,因此代码大约有450行。有没有什么方法可以减少代码,或者其他配置和构建作业的方法?
#!/usr/bin/env groovy
pipeline {
agent any
parameters {
choice(
choices: 'Job1\nJob2'\nJob3,
description: '',
name: 'Project'
)
}
stages {
stage ('callJob1') {
when {
expression { params.Project == 'Job1' }
}
steps{
build job: 'test1'
build job: 'test2'
.
.
.
.
.
}
}
stage('callJob2'){
when{
expression { params.Project == 'Job2'}
}
steps{
build job: 'test3'
build job: 'test4'
.
.
.
.
.
}
}
stage('callJob3'){
when{
expression { params.Project == 'Job3'}
}
steps{
build job: 'test5'
build job: 'test6'
.
.
.
.
.
}
}
}
}发布于 2019-05-29 15:44:27
尝试分步提取公共部分,并在jenkinsfile中定义方法。在jenkinsfile A中定义的方法也可以在同一项目中的jenkinsfile B中调用。
例如:
def func() {
}
.
.
stages {
stage('Job1'){
steps {
script {
func()
}
}
}
stage('Job2'){
steps {
script {
func()
}
}
}
}https://stackoverflow.com/questions/56354865
复制相似问题