From f0c2532dd4884aff90adb35a3f5e88beaf539df8 Mon Sep 17 00:00:00 2001 From: harishjangam6979 <60278055+harishjangam6979@users.noreply.github.com> Date: Mon, 7 Jun 2021 16:17:19 -0700 Subject: [PATCH 1/2] Add files via upload Get the list of offline Shared agents and bring them online --- shared-agent-bring-onine.groovy | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 shared-agent-bring-onine.groovy diff --git a/shared-agent-bring-onine.groovy b/shared-agent-bring-onine.groovy new file mode 100644 index 0000000..d7e0bef --- /dev/null +++ b/shared-agent-bring-onine.groovy @@ -0,0 +1,26 @@ +/** + Author: Harish Jangam + Description: Get the list of offline Shared agents and bring them online + **/ + +import hudson.slaves.* +import static com.cloudbees.opscenter.server.persistence.SlaveLeaseTable.getLeases; + + +def SharedAgentstatus(Slave) { + def online = false + if (Slave instanceof com.cloudbees.opscenter.server.model.SharedSlave) { + online = Slave.getOfflineCause() == null + if(!online){ + println(Slave.name + ' is currently Offline, hence bringing it online \t') + //aSlave.doEnable() // comment - to get the list of offline agents, // Uncomment - to bring the agent online + } + } +} + +Jenkins.instance.allItems.grep { + it.class.name == 'com.cloudbees.opscenter.server.model.SharedSlave' +}.each { + SharedAgentstatus(it) +} +println '' From c313dc90a924ed23077ad30b5a331016c2c50ad6 Mon Sep 17 00:00:00 2001 From: harishjangam6979 <60278055+harishjangam6979@users.noreply.github.com> Date: Thu, 10 Jun 2021 15:33:42 -0700 Subject: [PATCH 2/2] Update shared-agent-bring-onine.groovy Updating correct variable --- shared-agent-bring-onine.groovy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shared-agent-bring-onine.groovy b/shared-agent-bring-onine.groovy index d7e0bef..f22d6d5 100644 --- a/shared-agent-bring-onine.groovy +++ b/shared-agent-bring-onine.groovy @@ -13,7 +13,7 @@ def SharedAgentstatus(Slave) { online = Slave.getOfflineCause() == null if(!online){ println(Slave.name + ' is currently Offline, hence bringing it online \t') - //aSlave.doEnable() // comment - to get the list of offline agents, // Uncomment - to bring the agent online + //Slave.doEnable() // comment - to get the list of offline agents, // Uncomment - to bring the agent online } } }