这就是我如何解决我对库中定义的共享参数的需求,同时各个作业定义自己的自定义参数。这是我的Jenkinsfile
样子:
#!groovy
@Library('my-library@master') _
properties([
parameters([
string(name: 'PARAM_A', defaultValue: '1', description: 'Aaa'),
string(name: 'PARAM_B', defaultValue: '2', description: 'Bbb'),
string(name: 'PARAM_C', defaultValue: '3', description: 'Ccc'),
] + runTest.commonJobParams())
])
runTest(
params: params,
)
这就是vars/runTest.groovy
我的图书馆的样子:
def commonJobParams() {
return [
string(
name: 'GOLDEN',
defaultValue: '999',
description: 'Description of param from library',
),
]
}
def call(Map config) {
pipeline {
agent {
...
}
stages {
stage('Test') {
steps {
echo "Hello ${PARAM_A}"
echo "Hello ${PARAM_B}"
echo "Hello ${PARAM_C}"
echo "Hello ${GOLDEN}"
}
}
}
}
}