19

Can anyone explain the different between the execute groovy script and the execute system groovy script in jenkins? And how to call the script to slave using execute system groovy script.

Alexander Stohr
  • 159
  • 1
  • 18
user2400564
  • 4,619
  • 7
  • 24
  • 27

2 Answers2

13

To execute a groovy script on the slave machine, you should use groovy plugin

Quote

The plain "Groovy Script" is run in a forked JVM, on the slave where the build is run. It's the basically the same as running the "groovy" command and pass in the script.

First part of your question is answered in the same page

The system groovy script, OTOH, runs inside the Hudson master's JVM. Thus it will have access to all the internal objects of Hudson, so you can use this to alter the state of Hudson. It is similar to the Jenkins Script Console functionality.

Jayan
  • 18,003
  • 15
  • 89
  • 143
1

Another point on system Groovy scripts to be aware of. While the documentation says that it always runs on the Jenkins master, I've found through painful means that it isn't true if it's in a job that is triggered by another job. In that case, make sure you specifically restrict it to run on the master or bad things will happen.

Joel
  • 111
  • 13
  • 1
    This response isn't quite true. System Groovy scripts are used to access the Jenkins internals (e.g. Job/Build/Queue information) and as such the script itself run's on the Jenkins master, inside the Jenkins master JVM, regardless of which slave the job itself is running on. As an example, our Jenkins master has no executors, and never runs the builds. They are always run on the slaves, however the System Groovy scripts still run on the master JVM. – Nick Holt Jan 16 '19 at 18:30