Jenkins

Jenkins stage/step SKIP 하기

thxxyj 2024. 4. 29. 17:37
728x90

1. when 을 통한 SKIP

https://www.jenkins.io/doc/book/pipeline/syntax/#when

https://stackoverflow.com/questions/56148230/how-to-mark-jenkins-job-stage-as-skipped-for-scripted-pipeline

 

 

stage1 skipped

 

BRANCH_NAME = 'branch_name'

pipeline {
    agent any

    stages {
        stage('stage1') {
            when {
                expression { BRANCH_NAME == "master" }
            }
            steps {
                echo "Performing steps of stage1"
            }
            
        }
        stage('stage2') {
            steps {
                echo 'Performing steps of stage2'
            }
        }
    }
}

 

 

2. markStageSkippedForConditional 을 통한 SKIP

import org.jenkinsci.plugins.pipeline.modeldefinition.Utils

node() {
  stage('stage1'){
    echo 'stage 1'
  }
  stage('stage2'){
    if(true){
       echo 'skipping stage...'
       Utils.markStageSkippedForConditional('stage2')
    }else{
      echo 'This stage may be skipped'

    }
  }
  stage('stage3'){
    echo 'stage 3'
  }
}

 

 

 

728x90