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

When section not evaluated

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: Minor Minor
    • None

      When section doesn't get evaluated (stage always executed) when the pipeline {} definition is inside a shared library

      @Library('jenkins-pipelines') _
      ContinousIntegrationBoot {
             SKIP = [SCM:false, BUILD:false, TEST:false, QA: true, IT: true, DEPLOY: false]
             MAILS = ["xyz@xyz.es"]
      }
      
      

      The when sections are not evaluates and we must check with if{} in script{} section ....

      def call(body) {
      
          
          // evaluate the body block, and collect configuration into the object
          def config = [:]
          body.resolveStrategy = Closure.DELEGATE_FIRST
          body.delegate = config
          body()
      
          pipeline {
              options{
                  skipDefaultCheckout()
              }
          
              agent none
              // node
              stages {
                  stage('scm') {
                      when{
                          // Not executed when inside the library                     expression{
                              echo "Skip scm EXPRESSION is ${config.SKIP.SCM}"
                              return !config.SKIP.SCM
                          }
                      }
                      agent any
                      steps {
                          echo "Skip scm is ${config.SKIP.SCM}"
                          script {
                              if(!config.SKIP.SCM) {
                                  deleteDir()
                                  checkout scm
                              }
                          }
                      }
                  }
      ......................................
      
      

      Thanks

       

       

            abayer Andrew Bayer
            nicolasus Nico Navarrete
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: