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

Groovy script and scriptText REST interface should accept parameters

    XMLWordPrintable

    Details

    • Similar Issues:

      Description

      At the moment there is no way to pass parameters for groovy remote script execution via script or scriptText POST requests. One of the option that can be used to provide arguments can be implemented via POST request query attribute-value pairs, like

      http://localhost:8080/scriptText?param1=value1&param2=value2 ...

      Correspondingly, the groovy script can be provided with parameters using binding either for each attribute (excluding such default parameters like: script which contains the script code itself or r which corresponds to result, etc.), or via dedicated binding query or any suitable.

        Attachments

          Activity

          Hide
          grayaii Alex Gray added a comment -

          The workaround that I use is via the jenkins-cli:

          java -jar jenkins-cli.jar -remoting groovy foo.groovy myargs

           

          Ideally, the scriptText endpoint should support it.  I'm not sure how the jenkins-cli is doing it though.

          Show
          grayaii Alex Gray added a comment - The workaround that I use is via the jenkins-cli: java -jar jenkins-cli.jar -remoting groovy foo.groovy myargs   Ideally, the scriptText endpoint should support it.  I'm not sure how the jenkins-cli is doing it though.
          Hide
          allan_burdajewicz Allan BURDAJEWICZ added a comment -

          You could use the StaplerRequest to retrieve requests parameters with something like the following in the script:

          def request = org.kohsuke.stapler.Stapler.getCurrentRequest()
          
          def param1 = request.getParameter("param1")
          def param2 = request.getParameter("param2")
          
          [...]
          

          With curl, it would look like this:

          curl -k --user ${USER}:${TOKEN} "${JENKINS_URL}/scriptText" \
              --data-urlencode "script=$(< ./myScript.groovy)" \
              --data-urlencode "param1=value1" \
              --data-urlencode "param2=value2"
          
          Show
          allan_burdajewicz Allan BURDAJEWICZ added a comment - You could use the StaplerRequest to retrieve requests parameters with something like the following in the script: def request = org.kohsuke.stapler.Stapler.getCurrentRequest() def param1 = request.getParameter( "param1" ) def param2 = request.getParameter( "param2" ) [...] With curl, it would look like this: curl -k --user ${USER}:${TOKEN} "${JENKINS_URL}/scriptText" \ --data-urlencode "script=$(< ./myScript.groovy)" \ --data-urlencode "param1=value1" \ --data-urlencode "param2=value2"

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            kyr Kyr Shatskyy
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

              Dates

              Created:
              Updated: