Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-44511

Multibranch plugin with declarative pipelines checks out the project for skipped stages

    XMLWordPrintable

    Details

    • Similar Issues:

      Description

      I would like to execute 2 stages on 2 different nodes. First stage should be executed always, and the second under a certain condition.

      Everything works, except that when the second stage is not executed (the 'when' expression is not satisfied), a checkout of the repository is still done. 

      This is the Jenkinsfile:

      pipeline {
        agent { label 'node_1' }
      
        stages {
          stage("Stage 1") {
            steps {
              script {
                echo "Stage 1"
              }
            }
          }
      
          stage ('Stage 2') {
            when {
              expression { env.BRANCH_NAME == "master" }
            }
            agent { label 'node_2' }
            steps {
              script {
               echo "Stage 2"
             }
           }
         }
        }
      }

      The big problem with this is that in case the 'node_2' is executing other jobs, the current job cannot continue until this node has a free executor. 

       

        Attachments

          Activity

          suomiro Lucian Varlan created issue -
          suomiro Lucian Varlan made changes -
          Field Original Value New Value
          Labels checkout declarative pipeline checkout declarative multibranch pipeline
          Hide
          gdjennings Grant Jennings added a comment -

          Found this problem also. Definitely annoying. Have ECS cluster agents...have to wait for one to spin up just to decide not to run.

          Show
          gdjennings Grant Jennings added a comment - Found this problem also. Definitely annoying. Have ECS cluster agents...have to wait for one to spin up just to decide not to run.
          vaimr Denis Saponenko made changes -
          Component/s pipeline-model-definition-plugin [ 21706 ]
          Assignee Denis Saponenko [ vaimr ] Andrew Bayer [ abayer ]
          Hide
          vaimr Denis Saponenko added a comment -

          But it works:

           

          pipeline {
            agent { label 'node_1' }
          
            stages {
              stage("Stage 1") {
                steps {
                  script {
                    echo "Stage 1"
                  }
                }
              }
          
              stage ('Stage 2') {
                when {
                  expression { env.BRANCH_NAME == "master" }
                }
                steps {
                  node ('node_2') {
                    script {
                      echo "Stage 2"
                    }
                  }
               }
             }
            }
          }
          

          The problem in interpreting the scenario in the basic pipeline implementation.

           

          Show
          vaimr Denis Saponenko added a comment - But it works:   pipeline { agent { label 'node_1' } stages { stage( "Stage 1" ) { steps { script { echo "Stage 1" } } } stage ( 'Stage 2' ) { when { expression { env.BRANCH_NAME == "master" } } steps { node ( 'node_2' ) { script { echo "Stage 2" } } } } } } The problem in interpreting the scenario in the basic pipeline implementation.  
          Hide
          suomiro Lucian Varlan added a comment -

          Your example doesn't work. 'node' (or even 'agent') is not a valid step.

          Show
          suomiro Lucian Varlan added a comment - Your example doesn't work. 'node' (or even 'agent') is not a valid step.
          Hide
          abayer Andrew Bayer added a comment -

          A solution to this was added in Declarative 1.2.6 - the beforeAgent true option to put inside when. If given, the when will be evaluated before entering the agent for the stage.

          Show
          abayer Andrew Bayer added a comment - A solution to this was added in Declarative 1.2.6 - the beforeAgent true option to put inside when . If given, the when will be evaluated before entering the agent for the stage.
          abayer Andrew Bayer made changes -
          Resolution Fixed [ 1 ]
          Status Open [ 1 ] Resolved [ 5 ]
          Hide
          bitwiseman Liam Newman added a comment -

          Bulk closing resolved issues.

          Show
          bitwiseman Liam Newman added a comment - Bulk closing resolved issues.
          bitwiseman Liam Newman made changes -
          Status Resolved [ 5 ] Closed [ 6 ]

            People

            Assignee:
            abayer Andrew Bayer
            Reporter:
            suomiro Lucian Varlan
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: