在vars/myDeliveryPipeline.groovy
中,我有一个声明式管道的模板:
def call(Map pipelineParams) {
pipeline {
agent any
stages {
stage('checkout git') {
steps {
git branch: pipelineParams.branch, credentialsId: 'GitCredentials', url: pipelineParams.scmUrl
}
}
stage('build') {
steps {
sh 'mvn clean package -DskipTests=true'
}
}
stage ('test') {
steps {
parallel (
"unit tests": { sh 'mvn test' },
"integration tests": { sh 'mvn integration-test' }
)
}
}
}
}
}
在Jenkinsfile
中,我通过
myDeliveryPipeline(branch: 'master', scmUrl: 'ssh://git@myScmServer.com/repos/myRepo.git',
serverPort: '8080', server: 'dev-myproject.mycompany.com')
如何在parameters { ... }
中指定Jenkinsfile
指令并将这些参数传播到myDeliveryPipeline
?
是否会在Jenkinsfile
内创建一个接受参数的管道,然后让第一阶段实例化myDeliveryPipeline
是一种惯用的解决方案?