Child pages
  • Jenkins Script Console
42 more child pages

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: separate getting result so it is more clear

...

Code Block
languagegroovy
titleScript executes code on agent from Master Script Console
import hudson.util.RemotingDiagnostics
import jenkins.model.Jenkins
 
//groovy script you want executed on an agent
groovy_script = '''
println System.getenv("PATH")
println "uname -a".execute().text
'''.trim()
 
String result
Jenkins.instance.slaves.find { agent ->
    agent.name == 'your agent name'
}.with { agent ->
    result = RemotingDiagnostics.executeGroovy(groovy_script, agent.channel)
}
println result

Remote access

A Jenkins Admin can execute groovy scripts remotely by sending an HTTP POST request to /script/ url or /scriptText/.

...