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

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

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Major Major

      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.

       

          [JENKINS-46476] Environment and Options blocks do not take effect from within groovy shared variable

          Kurt Routley created issue -
          Kurt Routley made changes -
          Summary Original: Environment and Options blocks do not take effect from groovy shared variable New: Environment and Options blocks do not take effect from within groovy shared variable
          Kurt Routley made changes -
          Link New: This issue is related to JENKINS-42224 [ JENKINS-42224 ]
          Andrew Bayer made changes -
          Component/s New: pipeline-model-definition-plugin [ 21706 ]
          Component/s Original: pipeline [ 21692 ]
          Andrew Bayer made changes -
          Labels Original: environment options pipeline New: environment options pipeline triaged-2018-11

            Unassigned Unassigned
            kroutley Kurt Routley
            Votes:
            2 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated: