Execute Groovy script in Jenkins remotely Bee Bot July 13, 2022 13:16 Updated The content of this article has moved to the new documentation site. Related articles Groovy to list all jobs Pipeline - Build failed due to MissingPropertyException: No such property: env How to Trigger Multibranch Jobs from Bitbucket Server? Why is my instance not getting the right information from CloudBees Update Center starting on October 19th, 2021? How to block access to URLs vulnerable to SECURITY-2469/CVE-2021-21678 Comments 3 comments Sort by Date Votes Praveen Haldipur May 23, 2017 13:57 Wrote a groovy script works from the web console but fails with parsing errors when used from REST API. Why the diff? it fails on '&' i have embedded in some HTML that I am adding to summary action for a build. 0 Praveen Haldipur May 23, 2017 15:18 Need to use curl --data-urlencode when using REST API. That worked! 0 Ed Mason November 27, 2019 15:39 When I try this on Windows with a multi-line script I find that it only executes the first line. Any ideas? script test.groovy println 'starting script'println(Jenkins.instance.getAllItems(Job.class))println(Jenkins.instance.pluginManager.plugins) >curl.exe -d "script=$(type /temp/test.groovy)" -v --user <my_userid> https://<my_jenkins_server>/scriptText * upload completely sent off: 129 out of 129 bytes< HTTP/1.1 200 OK< Date: Wed, 27 Nov 2019 15:32:57 GMT< Server: Jetty(9.4.z-SNAPSHOT)< X-Content-Type-Options: nosniff< Content-Type: text/plain;charset=utf-8< Content-Length: 16<starting script* Connection #0 to host <my_jenkins_server> left intact 0 Please sign in to leave a comment.
Comments
3 comments
Wrote a groovy script works from the web console but fails with parsing errors when used from REST API. Why the diff?
it fails on '&' i have embedded in some HTML that I am adding to summary action for a build.
Need to use curl --data-urlencode when using REST API. That worked!
When I try this on Windows with a multi-line script I find that it only executes the first line. Any ideas?
script test.groovy
println 'starting script'
println(Jenkins.instance.getAllItems(Job.class))
println(Jenkins.instance.pluginManager.plugins)
>curl.exe -d "script=$(type /temp/test.groovy)" -v --user <my_userid> https://<my_jenkins_server>/scriptText
* upload completely sent off: 129 out of 129 bytes
< HTTP/1.1 200 OK
< Date: Wed, 27 Nov 2019 15:32:57 GMT
< Server: Jetty(9.4.z-SNAPSHOT)
< X-Content-Type-Options: nosniff
< Content-Type: text/plain;charset=utf-8
< Content-Length: 16
<
starting script
* Connection #0 to host <my_jenkins_server> left intact
Please sign in to leave a comment.