Jenkins pipeline if else not working

后端 未结 3 426

I am creating a sample jenkins pipeline, here is the code.

pipeline {
    agent any 

    stages {    
        stage(\'test\') { 
            steps { 
                   


        
3条回答
  •  后悔当初
    2021-01-30 05:37

    It requires a bit of rearranging, but when does a good job to replace conditionals above. Here's the example from above written using the declarative syntax. Note that test3 stage is now two different stages. One that runs on the master branch and one that runs on anything else.

    stage ('Test 3: Master') {
        when { branch 'master' }
        steps { 
            echo 'I only execute on the master branch.' 
        }
    }
    
    stage ('Test 3: Dev') {
        when { not { branch 'master' } }
        steps {
            echo 'I execute on non-master branches.'
        }
    }
    

提交回复
热议问题