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

Issue with passing build parameters to Library vars closure

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed (View Workflow)
    • Priority: Minor
    • Resolution: Not A Defect
    • Component/s: pipeline
    • Labels:
    • Environment:
    • Similar Issues:

      Description

      Basically I can't pass build properties to Library var call without extra nonsense.

      tc_test{
       repo = 'test1'
       folder = 'test2'
       submodules = true
       refs = params.GitCheckout
      }
      

      results in error

      java.lang.NullPointerException: Cannot get property 'GitCheckout' on null object

      This, however, works:

      def a1 = params.GitCheckout
      tc_test{
        repo = 'tc3'
        folder = 'tc3'
        submodules = true
        refs = a1
      }
      

      I'm not really good with groovy, so sorry if it's something obvious.

        Attachments

          Activity

          Hide
          jglick Jesse Glick added a comment -

          From inside the closure, there is a different scope.

          Given the subtle aspects of the “builder” syntax I do not really recommend it for library authors. Simpler and more reliable to define a function taking a Map<String, Object> of inputs, and pass it arguments like

          tc_test [
            repo: 'test1',
            folder: 'test2',
            submodules: true,
            refs = params.GitCheckout
          ]

          which should work since the map is constructed with its actual values by the script, then passed as data to the library.

          Show
          jglick Jesse Glick added a comment - From inside the closure, there is a different scope. Given the subtle aspects of the “builder” syntax I do not really recommend it for library authors. Simpler and more reliable to define a function taking a Map<String, Object> of inputs, and pass it arguments like tc_test [ repo: 'test1' , folder: 'test2' , submodules: true , refs = params.GitCheckout ] which should work since the map is constructed with its actual values by the script, then passed as data to the library.
          Hide
          trueconf_kiryanov Alexey Kiryanov added a comment -

          Yep. that worked perfectly.

          Show
          trueconf_kiryanov Alexey Kiryanov added a comment - Yep. that worked perfectly.
          Hide
          shaiton Kevin Raymond added a comment - - edited

          Hi there,

          Sorry to bump into this close ticket but I should miss something, I can't use properly the solution proposed here. I always get the following error:
          .NoSuchMethodError: No such DSL method 'getAt' found among steps
          The signature of my "cloneProject.groovy" method is:

           

          call(Map parameters) {
           def project = get.parameters('project', 'false')
          

           

          Edit: sorry for the burden, the get.parameters if wrong in this case I dunno where I took it from... parameters.find() resolve my issue.

           

           

          Show
          shaiton Kevin Raymond added a comment - - edited Hi there, Sorry to bump into this close ticket but I should miss something, I can't use properly the solution proposed here. I always get the following error: .NoSuchMethodError: No such DSL method 'getAt' found among steps The signature of my "cloneProject.groovy" method is:   call(Map parameters) {  def project = get.parameters( 'project' , ' false ' )   Edit: sorry for the burden, the get.parameters if wrong in this case I dunno where I took it from... parameters.find() resolve my issue.    

            People

            • Assignee:
              Unassigned
              Reporter:
              trueconf_kiryanov Alexey Kiryanov
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: