Skip to main content

Groovy Script: How to iterate through Jenkins Masters from JOC?

Comments

6 comments

  • Daniel Ritchie

    Here's the related script that I found.  Do I need to "execute remote script on master" from the JOC to accomplish this?  I'm hoping there might be a more direct way.

     

    https://github.com/cloudbees/jenkins-scripts/blob/master/print-masters-plugins.groovy#L28

     

     

    0
  • Denys Digtiar

    You can create a Cluster Operation project which allows sending Groovy scripts to execute on connected Masters of your choice. 

    https://go.cloudbees.com/docs/cloudbees-documentation/cjoc-user-guide/index.html#_cluster_operations

    0
  • Daniel Ritchie

    That's a great idea Denys.  Will be good for a few other things we are trying to accomplish as well.

    I can see that Cluster Operations is able to run a single script in parallel across multiple masters, but is there a way to consolidate the output?

    My original thinking was that I could have a single map/array/etc. and I could loop each master and update the counts.  Then, I would end up with one single output (which is a report from all of the masters) instead of duplicated info from each master that I then have to concatenate somehow.

    Helpful either way, thanks!

    0
  • Daniel Ritchie

    It doesn't look like a Cluster Operation will work for this. 

    It seems like the Cluster Operations script run as an isolate script on each master; I can't see any way to report back to the Operations Center, and even if I could (say as output) that doesn't allow me to write another script to concatenate/interpret all of the results.

    Is there an equivalent to http://<JOC URL>/script that I can setup as a job that runs groovy script within the context of the JOC?

    0
  • Daniel Ritchie

    Updating as an FYI for anyone else who comes across this.

    So far I think the only possible solution is to navigate to JOC/script and run groovy which executes code on each master, like this:
    https://github.com/cloudbees/jenkins-scripts/blob/master/print-masters-plugins.groovy#L30

    From there I can create a return object that can handle the response within the JOC's script, where I can aggregate results from all of the masters.

    0
  • Denys Digtiar

    The Jenkins CLI has a script subcommand and there is an HTTP endpoint as well. Therefore, it should be possible to create a Freestyle job that executes the script whenever necessary.

    https://wiki.jenkins.io/display/JENKINS/Jenkins+Script+Console

    0

Please sign in to leave a comment.

About CloudBees Support

Our Support Engineers are available to help with any questions or problems you may have with any of our products.