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

NodeLabel parameters are null objects in pipeline script params

    XMLWordPrintable

Details

    Description

      Accessing the parameter with param will give you a null object, but accessing it through env and global will give you the string of one node.

      Example:

      properties ([
          parameters([
              [
                   $class: 'BooleanParameterDefinition',
                   defaultValue: false,
                   description: 'This will do a clean and build of the project.',
                   name: 'Rebuild'
              ],
              [
                   $class: 'NodeParameterDefinition',
                   allowedSlaves: ['ALL (no restriction)'],
                   defaultSlaves: ['master'],
                   description: 'What nodes to run the build on.',
                   name: 'NODE_PARAM',
                   nodeEligibility: [$class: 'AllNodeEligibility'],
                   triggerIfResult: 'allowMultiSelectionForConcurrentBuilds'
              ]
          ])
      ])
      
      echo "NODE_PARAM: " + NODE_PARAM.getClass().toString()
      echo "env.NODE_PARAM: " + env.NODE_PARAM.getClass().toString()
      echo "params.NODE_PARAM: " + params.NODE_PARAM.getClass().toString()
      
      

      Will give you this output:

      [Pipeline] echo
      NODE_PARAM: class java.lang.String
      [Pipeline] echo
      env.NODE_PARAM: class java.lang.String
      [Pipeline] echo
      params.NODE_PARAM: class org.codehaus.groovy.runtime.NullObject
      

      As you can see, only params.NODE_PARAM is null. 

      The problem is that I can not use env.NODE_PARAM or NODE_PARAM to get multiple selection of nodes, as those are only a string representation of a single node.

       

      Attachments

        Activity

          macdrega Joerg Schwaerzler added a comment - - edited

          Can confirm. Another issue would be that only the params. version would return the default value for the label or node paramter when called for the first time.

          macdrega Joerg Schwaerzler added a comment - - edited Can confirm. Another issue would be that only the params. version would return the default value for the label or node paramter when called for the first time.
          mafjmafj Maciej added a comment -

          I can see the issue on Jenkins 2.321     org.jenkins-ci.plugins:nodelabelparameter:1.9.2

          Also when running from script console the builds node parameter value is always null.

           

          Running in script console

          def buildingJobs = Jenkins.instance.getAllItems(Job.class).findAll { it.isBuilding() }
          buildingJobs.each { job->
              allRuns = job._getRuns()
              allRuns.each { item ->
                
                  def runningLabel
                  if (item.isBuilding()) {
                      runningLabel = item.getExecutor().getOwner().getNode().getNodeName()
                  }
          
                  def scheduledLabel = 'zzz';
                  // get parameters
                  def parameters = item?.actions.find{ it instanceof ParametersAction }?.parameters
                  parameters.each {
                      if( it.name == "PARAM_WITH_LABEL") {
                          scheduledLabel = it.value
                      }
                      //println "        ${it.name}: ${it.value}"
                  }
                println "'${item.getUrl()}' ${item.isBuilding()} '${scheduledLabel}' '${runningLabel}'"
              }
          }
          

           

          I get something alike

          'job/dibench/22740/' true 'null' 'nodename1'
          'job/dibench/22739/' true 'null' 'nodename2'
          'job/dibench/22738/' false 'null' 'null'
          'job/dibench/22737/' false 'null' 'null'
          mafjmafj Maciej added a comment - I can see the issue on Jenkins 2.321     org.jenkins-ci.plugins:nodelabelparameter:1.9.2 Also when running from script console the builds node parameter value is always null.   Running in script console def buildingJobs = Jenkins.instance.getAllItems(Job.class).findAll { it.isBuilding() } buildingJobs.each { job->     allRuns = job._getRuns()     allRuns.each { item ->                def runningLabel         if (item.isBuilding()) {             runningLabel = item.getExecutor().getOwner().getNode().getNodeName()         }         def scheduledLabel = 'zzz' ;         // get parameters         def parameters = item?.actions.find{ it instanceof ParametersAction }?.parameters         parameters.each {           if ( it.name == "PARAM_WITH_LABEL" ) {                 scheduledLabel = it.value             }             //println "        ${it.name}: ${it.value}"         }     println " '${item.getUrl()}' ${item.isBuilding()} '${scheduledLabel}' '${runningLabel}' "     } }   I get something alike 'job/dibench/22740/' true ' null ' 'nodename1' 'job/dibench/22739/' true ' null ' 'nodename2' 'job/dibench/22738/' false ' null ' ' null ' 'job/dibench/22737/' false ' null ' ' null '

          People

            Unassigned Unassigned
            snellingen Matias Snellingen
            Votes:
            11 Vote for this issue
            Watchers:
            13 Start watching this issue

            Dates

              Created:
              Updated: