将作业参数传递到模板化声明式管道

时间:2018-11-05 21:25:25

标签: jenkins jenkins-pipeline

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是一种惯用的解决方案?

0 个答案:

没有答案