简体   繁体   English

Jenkins 多分支管道:Select 仅构建 2 个特定分支

[英]Jenkins MultiBranch Pipeline: Select to build only 2 specific branches

I have a Jenkins MultiBranch project and I want the test circle to run only on two specific branches on master and on dev .我有一个 Jenkins MultiBranch 项目,我希望测试圈只在masterdev上的两个特定分支上运行。 I tried to add on all stages the following我尝试在所有阶段添加以下内容

when { anyOf { branch 'master'; branch 'dev' } }

but the only thing I managed to achieve was to deactivate all branch runs但我唯一能做到的就是停用所有分支运行

Here is my full pipeline Jenkinsfile这是我的完整管道 Jenkinsfile

    pipeline {
        agent any
        triggers {
            cron('H 0 * * *')
        }
        options {
            disableConcurrentBuilds()
        }
        stages {
        stage('Prepare env') {
            when { anyOf { branch 'master'; branch 'dev' } }
            steps {
               sh 'rm -rf venv'
               sh 'rm -rf "${WORKSPACE}/uploads"'
               sh 'rm -rf "${WORKSPACE}/downloads"'
               sh 'mkdir "${WORKSPACE}/uploads"'
               sh 'mkdir "${WORKSPACE}/downloads"'
               catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE')
               {
                     sh 'docker kill $(docker ps -q)'
                     sh 'docker rm $(docker ps -a -q)'
             sh 'docker volume rm $(docker volume ls -q)'
               }
    
            }
        }
        
            stage('Start Services') {
            when { anyOf { branch 'master'; branch 'dev' } }
                steps {
           
                }
            }
    
            stage('Test Common') {
            when { anyOf { branch 'master'; branch 'dev' } }
                steps {
    
                }
            }
    
        stage('Test Validations') {
            when { anyOf { branch 'master'; branch 'dev' } }
                steps {
    
                }
            }
    
            stage('Test CSV Issuance') {
            when { anyOf { branch 'master'; branch 'dev' } }
                steps {
    
                }
            }
     
        
            stage('Test XLS Issuance') {
            when { anyOf { branch 'master'; branch 'dev' } }
                steps {
    
                }
            }
     
    
        
            stage('Clean env') {
            when { anyOf { branch 'master'; branch 'dev' } }
                steps {
                   sh 'rm -rf venv'
                   sh 'rm -rf "${WORKSPACE}/uploads"'
                   sh 'rm -rf "${WORKSPACE}/downloads"'
                   catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE')
                   {
                      sh 'docker kill $(docker ps -q)'
                      sh 'docker rm $(docker ps -a -q)'
                      sh 'docker volume rm $(docker volume ls -q)'
                   }
                }
        }
}

Can you post the full pipeline you have?您可以发布您拥有的完整管道吗?

You would use the when block on the stage you want run only on the two branches eg您将在只想在两个分支上运行的舞台上使用when块,例如

pipeline {
    agent any
    stages
    {
        stage ("Testing") {
            when {
                anyOf {
                    branch 'master'
                    branch 'dev'
                }
            }
            steps {
                echo "run testing"
            }
        }
        stage ("everything") {
            steps{
                echo "run on all branches"
            }
        }
    }
}

tested pipeline测试管道

pipeline { 
    agent any
    stages {
        stage("stage") {
            when { anyOf { branch 'master'; branch 'dev' } }
            steps {
                echo "Hello"
            }
        }
    }
}

on master在主人

[Pipeline] stage
[Pipeline] { (stage)
[Pipeline] echo
Hello
[Pipeline] }
[Pipeline] // stage

On Fish关于鱼

[Pipeline] stage
[Pipeline] { (stage)
Stage "stage" skipped due to when conditional
[Pipeline] }
[Pipeline] // stage

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Jenkins Multibranch管道:如何选择构建节点? - Jenkins Multibranch pipeline: How to select a build node? gradle build with subprojects, git feature branches and jenkins multibranch pipeline: 如何只在受影响的子项目上运行测试 - gradle build with subprojects, git feature branches and jenkins multibranch pipeline: how to only run tests on affected subprojects Jenkins 多分支管道在不相关的分支上触发管道 - Jenkins multibranch pipeline triggers pipeline on unrelated branches Jenkins-多分支流水线在推送上构建 - Jenkins - Multibranch pipeline build on push 获取 Jenkins 多分支管道中的分支列表 - Get list of branches in Jenkins multibranch pipeline Jenkins具有多个仓库的多分支管道,仅用于更改的仓库 - Jenkins multibranch pipeline with multiple repo to build for the changed repo only Jenkins Pipeline 在 pull/pr 上构建特定的分支 - Jenkins Pipeline build specific branches on pull/pr Jenkins 多分支管道仅用于子文件夹 - Jenkins multibranch pipeline only for subfolder Jenkins 多分支管道 postbuild 仅在特定分支上(声明性) - Jenkins multibranch pipeline postbuild only on specific branch (declarative) Jenkins 从另一个多分支管道构建多分支管道 - Jenkins build multibranch pipeline from another multibranch pipeline
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM