A Jenkins Admin can execute groovy scripts remotely by sending an HTTP POST request to /script/ url or /scriptText/.
curl example via bash
[code]
curl -d “script=<your_script_here>” https://jenkins/script
# or to get output as a plain text result (no HTML)
curl -d “script=<your_script_here>” https://jenkins/scriptText
[/code]
curl submitting groovy file via bash
[code]
curl –data-urlencode “script=$(< ./somescript.groovy)” https://jenkins/scriptText
[/code]
curl submitting groovy file providing username and password via bash
[code]
curl –user ‘username:password’ –data-urlencode “script=$(< ./somescript.groovy)” https://jenkins/scriptText
[/code]
Jenkins CLI offers the possibility to execute groovy scripts remotely using groovy command or execute groovy interactivelly via groovysh.
[code]
java -jar jenkins-cli.jar -noCertificateCheck -s https://10.0.0.91/ groovy disableEnableJobsMatchingPattern.groovy jobPattern=build_git_auto disableOrEnable=disable –username 12345 –password banana
[/code]
Reference
https://wiki.jenkins.io/display/JENKINS/Jenkins+Script+Console
- How to save 80% of the Treatment Cost using Medical Tourism? - January 13, 2025
- Best AI tools and websites to travel blogger or travel video & audio creator - January 12, 2025
- Deep Dive & Troubleshoot using Kubernetes logs & its Structure & Location - January 12, 2025