All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.liferay.jenkins.results.parser.dependencies.set-slave-status.groovy Maven / Gradle / Ivy

The newest version!
import hudson.slaves.OfflineCause;
import hudson.slaves.OfflineCause.ByCLI;
import hudson.slaves.SlaveComputer;

String slaves = "${slaves}";

for (String slave : slaves.split(",")) {
	Hudson hudson = Hudson.instance;

	Slave slaveObject = hudson.getNode(slave.trim());

	SlaveComputer slaveComputer = slaveObject.getComputer();

	try {
		println(slaveComputer.getName() + " is online: " + slaveComputer.isOnline());

		boolean offlineStatus = ${offline.status};

		OfflineCause offlineCause = new OfflineCause.ByCLI("${offline.reason}");

		if (offlineStatus) {
			println("Setting " + slaveComputer.getName() + " to offline");
		}
		else {
			println("Setting " + slaveComputer.getName() + " to online");
		}

		slaveComputer.setTemporarilyOffline(offlineStatus, offlineCause);

		println(slaveComputer.getName() + " is online: " + slaveComputer.isOnline());
	}
	catch (Exception exception) {
		exception.printStackTrace();
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy