如何为Jenkins管道中的不同阶段设置不同的分支

时间:2018-06-15 10:47:15

标签: jenkins jenkins-pipeline

我有下一个管道:

pipeline {
    agent any
    stages {
        stage('CLEAN/INSTALL') {
            steps {
                sh 'mvn clean install -DskipTests'
            }
        }
        stage('RUN ON DEV') { //run against branch 'default'
            steps {
                sh 'mvn test  -Dspring.profiles.active=dev'
            }
        }
        stage('RUN ON QA') { //run against branch 'qa-stable'
            steps {
                sh 'mvn test  -Dspring.profiles.active=qa'
            }
        }
    }
}

我想针对不同的分支在不同的阶段运行测试: 怎么做到这一点?
谢谢!

1 个答案:

答案 0 :(得分:0)

只需添加一个sh'git checkout blah'

pipeline {
    agent any
    stages {
        stage('CLEAN/INSTALL') {
            steps {
                sh 'mvn clean install -DskipTests'
            }
        }
        stage('RUN ON DEV') { //run against branch 'default'
            steps {
                sh 'mvn test -Dspring.profiles.active=dev'
            }
        }
        stage('RUN ON QA') { //run against branch 'qa-stable'
            steps {
                // might need to stash if you have any unignored files changed by your build
                sh 'git checkout qa-stable'
                sh 'mvn test -Dspring.profiles.active=qa'
                // you might also want to re checkout your original branch
            }
        }
    }
}