Environment and Options blocks do not take effect from within groovy shared variable

This issue is archived. You can view it, but you can't modify it. Learn more

XMLWordPrintable

    • Type: Bug
    • Resolution: Unresolved
    • Priority: Major
    • Environment:

      We create a Declarative Pipeline script from within a groovy shared variable. The problem is the environment block and options block (specifically the disableConcurrentBuilds option) do not take effect from inside the groovy shared variable.

      Top-level jenkinsfile:

       

      #!groovy
      @Library("OurGroovyLibrary") _
      
      ourGroovySharedFunction([Arg: "SomeValue"])

       

      Groovy shared variable (ourGroovySharedFunction.groovy) :

       

      #!groovy
      
      def call(Map templateParams) {
        pipeline {
          agent {
            node {
              label 'ImportantLabel'
            }
          }
          environment {
            ImportantPath = 'C:/Some/Important/Path'
          }
          options {
            disableConcurrentBuilds() //BUG: This does not take effect, build still runs concurrently on slaves with more than 1 executor
          }
          stages {
            stage('Checking environment') {
              steps {
                echo "${env.getEnvironment()}" //BUG: ImportantPath is not present in env
              }
            }
          }
        }
      }

      Verified that the expected behavior occurs correctly when the declarative pipeline script is in the Jenkinsfile, but would prefer to have it in the groovy shared variable for scalability reasons.

       

            Assignee:
            Unassigned
            Reporter:
            Kurt Routley
            Archiver:
            Jenkins Service Account

              Created:
              Updated:
              Archived: