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

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

XMLWordPrintable

      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.

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

              Created:
              Updated:
              Resolved: