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

when expression is not validated when Jenkinsfile is loaded by other Jenkinsfile

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: Critical Critical

      Jenkinsfile1:

       

       pipeline {
             agent none
             options {
                  skipDefaultCheckout()
              }
              stages {
                stage('SCM') {
                     agent {
                         label 'master'
                     }
                     when {
                        expression { env.JOB_BASE_NAME != "íntegrator" }
                     }
                     steps {
                         script {
                              if("${env.JOB_BASE_NAME}" != 'integrator') {
                                 checkout scm
                              }
                         }
                         echo "SCM stuff..."
                     }
               }
      .....
      

      Jenkinsfile2: (job integrator will load this one )

      node('master') {
           ... checkout pull request ...
           load Jenkinsfile1
      }
      

      For some reason the when expression doesn't get validated (even tried wit "JOB_BASE_NAME == hjehkfjhdfhkl", still the scm stage gets executed. The if statement in the script block currently does the trick, but should not be needed.

       

      Some background: The reasons why I load jenkinsfile in another are because I work on a very large project where we splitted the tests in groups/different pipelines for convenient and maintenance and other reasons. However on a pull request, all these are controlled from one pipeline.

       

            Unassigned Unassigned
            roel0 roel postelmans
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: