Details

    • Type: Improvement
    • Status: Resolved (View Workflow)
    • Priority: Critical
    • Resolution: Fixed
    • Component/s: p4-plugin
    • Labels:
      None
    • Similar Issues:

      Description

      Hi,

       

      Is there a p4 way for below ?

       

      Please refer to https://jenkins.io/doc/tutorials/build-a-multibranch-pipeline-project/

      There's expression like

      stage('a') {
        when {
          branch 'dev'
        }
        steps {
      <snip>
        }
      }
      

       

      How can I use for this in p4?

       

        Attachments

          Activity

          Hide
          p4karl Karl Wirth added a comment -

          Hello Hokwang Lee,

          I have just tested and this seems to work with a multibranch pipeline. In the following only the branch 'main' exists:

          pipeline {
              agent any
              stages {
                  stage('Checkout') {
          	    when {
          	       branch 'BRANCH_DOES_NOT_EXIST'
          	    }
                      steps {
                          echo 'Don't show this...'
                      }
                  }
                  stage('Build') {
          	when {
          	       branch 'main'
          	    }
                      steps {
                          echo 'Building...'
                      }
                  }
                  stage('Test') {
                      steps {
                          echo 'Testing...'
                      }
                  }
              }
          }
          
          

          The relevant output I get in the console log is:

          [Pipeline] // stage
          [Pipeline] withEnv
          [Pipeline] {
          [Pipeline] stage
          [Pipeline] { (Checkout)
          Stage "Checkout" skipped due to when conditional
          [Pipeline] }
          [Pipeline] // stage
          [Pipeline] stage
          [Pipeline] { (Build)
          [Pipeline] echo
          Building...
          [Pipeline] }
          [Pipeline] // stage
          [Pipeline] stage
          [Pipeline] { (Test)
          [Pipeline] echo
          Testing...
          [Pipeline] }
          [Pipeline] // stage
          [Pipeline] }
          [Pipeline] // withEnv
          [Pipeline] }
          [Pipeline] // node
          [Pipeline] End of Pipeline
          

          Note that the stage 'Checkout' is successfully skipped when I run this against 'main' because it is not 'BRANCH_DOES_NOT_EXIST'.

           

           

          Show
          p4karl Karl Wirth added a comment - Hello Hokwang Lee , I have just tested and this seems to work with a multibranch pipeline. In the following only the branch 'main' exists: pipeline { agent any stages { stage( 'Checkout' ) { when { branch 'BRANCH_DOES_NOT_EXIST' } steps { echo 'Don' t show this ...' } } stage( 'Build' ) { when { branch 'main' } steps { echo 'Building...' } } stage( 'Test' ) { steps { echo 'Testing...' } } } } The relevant output I get in the console log is: [Pipeline] // stage [Pipeline] withEnv [Pipeline] { [Pipeline] stage [Pipeline] { (Checkout) Stage "Checkout" skipped due to when conditional [Pipeline] } [Pipeline] // stage [Pipeline] stage [Pipeline] { (Build) [Pipeline] echo Building... [Pipeline] } [Pipeline] // stage [Pipeline] stage [Pipeline] { (Test) [Pipeline] echo Testing... [Pipeline] } [Pipeline] // stage [Pipeline] } [Pipeline] // withEnv [Pipeline] } [Pipeline] // node [Pipeline] End of Pipeline Note that the stage 'Checkout' is successfully skipped when I run this against 'main' because it is not 'BRANCH_DOES_NOT_EXIST'.    
          Hide
          p4karl Karl Wirth added a comment -

          Seems to work.

          Show
          p4karl Karl Wirth added a comment - Seems to work.

            People

            • Assignee:
              Unassigned
              Reporter:
              luckyhorang Hokwang Lee
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: