Jenkins
Jenkins idle node 조회
thxxyj
2023. 6. 20. 11:54
728x90
jenkins에서 기본으로 제공하는 api (jenkins_ip/computer/api/json)에서 assignedLabels/idle을 통해 idle node 정보를 얻을 수 있지만,
groovy script에서도 idle node를 찾을 수 있다.
Computer.countBusy() == 0 인경우 node가 idle 상태이다.
/**
* Returns the number of {@link Executor}s that are doing some work right now.
*/
public final int countBusy() {
return countExecutors()-countIdle();
}
위 정보를 응용해서 특정 label의 노드의 상태를 다음과 같이 찾았다.
@NonCPS
// 특정 label을 가진 node이름 저장 (nodes(type: map)의 key로 저장)
def getNodeName(label) {
def nodes = [:]
Jenkins.get().computers.each { c ->
if (!c.isOffline()){
if (c.node.labelString.contains(label)) {
nodes.put(c.node.selfLabel.name, "")
}
}
}
return nodes
}
// getNodeName()에서 저장한 node의 countBusy()를 확인하여
// nodes(type: map)의 value에 idle 또는 working으로 저장
def checkNodeStatus(nodes) {
nodes.keySet()each() { n ->
def computer = Jenkins.getInstance().getComputer(n)
if(computer.countBusy()==0) {
nodes[n] = "idle"
} else {
nodes[n] = "working"
}
}
return nodes
}
https://www.tabnine.com/code/java/methods/hudson.model.Computer/countExecutors
728x90