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

Referencing a vars implicit property that is not set causes build to hang forever

      Using Jenkins 2.19.2.

      I'm trying to construct a shared library that can save params and global variables,with methods that can reference those variables. I'm building this step by step to make sure all the pieces work.

      I have this skeleton at this point:

      def setCurrentBuild(value) { currentBuild	= value; }
      def getCurrentBuild() { return currentBuild }
      
      def setJobName(value) { jobName	= value; }
      def getJobName() { return jobName }
      
      def setBuildURL(value) { buildURL = value; }
      def getBuildURL() { return buildURL }
      
      def setMechIdCredentials(value) { mechIdCredentials = value; }
      def getMechIdCredentials() { return mechIdCredentials }
      
      String toString() {
      	echo "Inside uslutils.toString()."
      	return "[currentBuild[${currentBuild}] jobName[${jobName}] buildURL[${buildURL}] mechIdCredentials[${mechIdCredentials}]"
      }
      

      And it's referenced from this Jenkinsfile:

      @Library("usl-pipeline-library@master")
      import com.att.usl.jenkins.BUILD_STATUS
      
      node {
          stage ("first") {
              uslutils.currentBuild   = currentBuild
              uslutils.jobName        = env.JOB_NAME
      	uslutils.buildURL       = env.BUILD_URL
      			
      	println "uslutils.toString()[${uslutils.toString()}]"
          }
      }
      

      I also have the following in "src":

      package com.att.usl.jenkins
      
      enum BUILD_STATUS {
      	IN_PROGRESS, SUCCESS, FAILED
      }
      

      When I run this Jenkinsfile, it hangs forever on the call to "toString()". I had to abort the build to get it to complete.

      I then changed the block above to this:

              uslutils.currentBuild   = currentBuild
              uslutils.jobName        = env.JOB_NAME
      	uslutils.buildURL       = env.BUILD_URL
      	uslutils.mechIdCredentials = "abc"
      

      And then I reran the build, and it completed successfully.

      Generally, all the parameters will be set, but I need a more robust solution for dealing with this situation.

          [JENKINS-42170] Referencing a vars implicit property that is not set causes build to hang forever

          David Karr created issue -
          David Karr made changes -
          Description Original: I'm trying to construct a shared library that can save params and global variables,with methods that can reference those variables. I'm building this step by step to make sure all the pieces work.

          I have this skeleton at this point:

          {code:java}
          def setCurrentBuild(value) { currentBuild = value; }
          def getCurrentBuild() { return currentBuild }

          def setJobName(value) { jobName = value; }
          def getJobName() { return jobName }

          def setBuildURL(value) { buildURL = value; }
          def getBuildURL() { return buildURL }

          def setMechIdCredentials(value) { mechIdCredentials = value; }
          def getMechIdCredentials() { return mechIdCredentials }

          String toString() {
          echo "Inside uslutils.toString()."
          return "[currentBuild[${currentBuild}] jobName[${jobName}] buildURL[${buildURL}] mechIdCredentials[${mechIdCredentials}]"
          }
          {code}

          And it's referenced from this Jenkinsfile:

          {code:java}
          @Library("usl-pipeline-library@master")
          import com.att.usl.jenkins.BUILD_STATUS

          node {
              stage ("first") {
                  uslutils.currentBuild = currentBuild
                  uslutils.jobName = env.JOB_NAME
          uslutils.buildURL = env.BUILD_URL

          println "uslutils.toString()[${uslutils.toString()}]"
              }
          }
          {code}

          I also have the following in "src":

          {code:java}
          package com.att.usl.jenkins

          enum BUILD_STATUS {
          IN_PROGRESS, SUCCESS, FAILED
          }
          {code}

          When I run this Jenkinsfile, it hangs forever on the call to "toString()". I had to abort the build to get it to complete.

          I then changed the block above to this:

          {code:java}
                  uslutils.currentBuild = currentBuild
                  uslutils.jobName = env.JOB_NAME
          uslutils.buildURL = env.BUILD_URL
          uslutils.mechIdCredentials = "abc"
          {code}

          And then I reran the build, and it completed successfully.

          Generally, all the parameters will be set, but I need a more robust solution for dealing with this situation.


          New: Using Jenkins 2.19.2.

          I'm trying to construct a shared library that can save params and global variables,with methods that can reference those variables. I'm building this step by step to make sure all the pieces work.

          I have this skeleton at this point:

          {code:java}
          def setCurrentBuild(value) { currentBuild = value; }
          def getCurrentBuild() { return currentBuild }

          def setJobName(value) { jobName = value; }
          def getJobName() { return jobName }

          def setBuildURL(value) { buildURL = value; }
          def getBuildURL() { return buildURL }

          def setMechIdCredentials(value) { mechIdCredentials = value; }
          def getMechIdCredentials() { return mechIdCredentials }

          String toString() {
          echo "Inside uslutils.toString()."
          return "[currentBuild[${currentBuild}] jobName[${jobName}] buildURL[${buildURL}] mechIdCredentials[${mechIdCredentials}]"
          }
          {code}

          And it's referenced from this Jenkinsfile:

          {code:java}
          @Library("usl-pipeline-library@master")
          import com.att.usl.jenkins.BUILD_STATUS

          node {
              stage ("first") {
                  uslutils.currentBuild = currentBuild
                  uslutils.jobName = env.JOB_NAME
          uslutils.buildURL = env.BUILD_URL

          println "uslutils.toString()[${uslutils.toString()}]"
              }
          }
          {code}

          I also have the following in "src":

          {code:java}
          package com.att.usl.jenkins

          enum BUILD_STATUS {
          IN_PROGRESS, SUCCESS, FAILED
          }
          {code}

          When I run this Jenkinsfile, it hangs forever on the call to "toString()". I had to abort the build to get it to complete.

          I then changed the block above to this:

          {code:java}
                  uslutils.currentBuild = currentBuild
                  uslutils.jobName = env.JOB_NAME
          uslutils.buildURL = env.BUILD_URL
          uslutils.mechIdCredentials = "abc"
          {code}

          And then I reran the build, and it completed successfully.

          Generally, all the parameters will be set, but I need a more robust solution for dealing with this situation.


          AFAICT, this is a duplicate of JENKINS-31484.

          If the (implicit) uslutils.mechIdCredentials variable is not set, then trying to resolve the GString ${mechIdCredentials} will call the getMechIdCredentials() method, which will then call itself trying to return mechIdCredentials, so you end up in an infinite loop.

          Christopher Orr added a comment - AFAICT, this is a duplicate of JENKINS-31484 . If the (implicit) uslutils.mechIdCredentials variable is not set, then trying to resolve the GString ${mechIdCredentials } will call the getMechIdCredentials() method, which will then call itself trying to return mechIdCredentials , so you end up in an infinite loop.
          Jesse Glick made changes -
          Link New: This issue duplicates JENKINS-31484 [ JENKINS-31484 ]
          Jesse Glick made changes -
          Resolution New: Duplicate [ 3 ]
          Status Original: Open [ 1 ] New: Resolved [ 5 ]

            Unassigned Unassigned
            dkarr David Karr
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: