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

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

XMLWordPrintable

    • 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.

       

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

              Created:
              Updated: