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

Declarative pipelines inside Global libraries scripts (vars/.groovy) does not evaluate properly conditional in "if" clauses

XMLWordPrintable

      I've tried to move an entire declarative pipeline to a vars/.groovy file in order to globalize it in a shared library using new 1.2 declarative (as per documentation here

      I have these files:

      DeclataviePipeline.groovy

       

      def call(String rutaPomXml, String rutaPomXmlEAR, String contextoUrl, Tipo tipo) {
      [...] //Some other stuffs
       pipeline { 
           [...] //Some other stuffs
            stage('Preparing environment') {
                agent { label 'linux' }
                steps {
                    preparaEntorno esLibreria: false
                 }
            [...] //Some other stuffs
      }
      

      preparaEntorno.groovy:

      def call(args) {
        echo "Preparando entorno..."
        def esLibreria = args.esLibreria?:false
        echo "Is library? ${esLibreria}"
      
        if(esLibreria) {
            echo "Preparing environment for library" 
        } else {
            echo "Preparing environment for app" 
        }
      [...] //Some other stuffs
      

      When pipeline runs, argument "esLibreria" is passed as "false" in preparaEntorno command but in console, I can see these messages:

      [Pipeline] echo
      Is library?? false
      [Pipeline] echo
      Preparing environment for library
      

      instead of

      "Preparing environment for app" 

      It works when pipeline is not in a .groovy file in a shared library.

        1. DeclataviePipeline.groovy
          0.1 kB
          Jesús Lunar Pérez
        2. prepareEnvironment.groovy
          0.4 kB
          Jesús Lunar Pérez
        3. preparingEnvironmentStage.groovy
          0.5 kB
          Jesús Lunar Pérez

            abayer Andrew Bayer
            jlp01 Jesús Lunar Pérez
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: