Created
May 24, 2019 06:54
-
-
Save jiahut/cd4949a2c4d2b43ca9732e20829baa59 to your computer and use it in GitHub Desktop.
jenkinsCli execute groovy script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.github.jiahut | |
import jenkins.model.Jenkins; | |
import hudson.remoting.*; | |
import jenkins.security.MasterToSlaveCallable; | |
import org.jenkinsci.remoting.RoleChecker; | |
import java.util.*; | |
public final class GetSystemProperties extends MasterToSlaveCallable<Properties,RuntimeException> { | |
public Properties call() { | |
return System.getProperties(); | |
} | |
private static final long serialVersionUID = 1L; | |
} | |
println "Jenkins version: $Jenkins.version " | |
println "Groovy version: $GroovySystem.version" | |
for (node in Jenkins.getInstance().getComputers()) { | |
def slave = node | |
// for (slave in hudson.model.Hudson.instance.slaves) { | |
// def rtm = node.getMonitors() | |
// prinltn rtm | |
// println node | |
def channel = slave.getChannel() | |
def loadingTime = channel.call(new hudson.slaves.SlaveComputer.LoadingTime(false)); | |
println loadingTime | |
// def sysProp = channel.call(new GetSystemProperties()); | |
// println sysProp | |
def sizeOfItems = channel.call(new MasterToSlaveCallable<Integer, IOException>() { | |
private static final long serialVersionUID = 1L; | |
public Integer call() throws IOException { | |
// this portion executes inside the Jenkins server JVM. | |
return Jenkins.getInstance().getItems().size(); | |
} | |
}) | |
println sizeOfItems | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment