首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用jenkins-cli检查jenkins节点连接状态

如何使用jenkins-cli检查jenkins节点连接状态
EN

Stack Overflow用户
提问于 2017-06-05 05:32:10
回答 2查看 10.9K关注 0票数 4

我正在尝试检查特定的Jenkins节点是否使用詹金斯连接。要获取节点详细信息,我可以使用get-node命令,它以xml的形式返回详细信息。

代码语言:javascript
复制
<?xml version="1.0" encoding="UTF-8"?>
<slave>
<name>20170602_jenkins_slave_002</name>
<description>10.49.82.46</description>
<remoteFS>c:\\jenkins_root</remoteFS>
<numExecutors>1</numExecutors>
<mode>EXCLUSIVE</mode>
<retentionStrategy class="hudson.slaves.RetentionStrategy$Always"/>
<launcher class="hudson.slaves.JNLPLauncher"/>
<label>20170602_jenkins_slave_002</label>
<nodeProperties/>
<userId>admin</userId>
</slave>

但是它不包括节点状态。任何人都知道如何通过Jenkins cli检查节点状态。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2017-06-05 07:08:05

由于我不知道使用詹金斯-克莱的方法,我的建议是使用REST:

代码语言:javascript
复制
http://jenkins.example.com/computer/:name/api/json

返回包含offline字段的JSON数据。

您可以从以下URL获得有关所有代理(此处称为计算机)的概述:

代码语言:javascript
复制
http://jenkins.example.com/computer/api/json?pretty=true
票数 8
EN

Stack Overflow用户

发布于 2020-11-24 15:37:46

我们可以使用管道来实现这一点。我在windows VDI机器上使用了groovy脚本,下面是脚本。

管道{代理无阶段{

代码语言:javascript
复制
  stage('Agent Health check step') {
        options {
            timeout(time:5, unit: 'MINUTES')
        }
        agent {
            label "master"
        }
    steps { 
    
        script {
    
            def agStatusList = []
            
            def agentsMap = [VDI1:"XYZ@gmail.com", VDI2:"XYZ2@gmail.com", VDI3:"XYZ@gmail.com", VDI4:"himesh.patel@gmail.com"]
            
            String agEmlTo=''
            
            for (agSlave in hudson.model.Hudson.instance.slaves) {
                    def agName=agSlave.name
                    def agOwner=agentsMap.get(agName)
                    def agStatus=agSlave.getComputer().isOnline()
                    
                    
                    
                    if (agStatus != true ){
                        
                        echo "Node is offline"
                        echo " "    
                        agStatusList += agName + " node is offline" + " and owner is " + agOwner
                        
                        if(agStatus != true && agOwner != null){
                        
                            if (agEmlTo == null || agEmlTo.trim().isEmpty()){ 
                                agEmlTo = agOwner
                            } else{
                                agEmlTo += (','+agOwner) 
                            }
                        

                        
                        }
                        
                    }else{
                    
                        echo "Node is online"
                        echo " "
                        agStatusList += agName + " node is online" + " and owner is " + agOwner
                        
                    }
                            
            }
            
             println agStatusList
             
             println agEmlTo
             
            if (agEmlTo != null && !agEmlTo.trim().isEmpty()) {
                
                echo "Sending email to the owners of offline Nodes"
                
                string agEmlCc='123@gmail.com'
                string agEmlFrom='JenkinsServer@gmail.com'
                String agEmlHdr='[Notification] Your Windows VDI agent is offline'
                
                String agEmlBody='Hello, \n \nThe Windlows VDI agent assigned to you seems offline now. Please check the Windows VDI machine and get it connected ASAP.\n \n *This E-mail is from Automated process. Please do not respond directly to this e-mail as the originating e-mail account is not monitored*'
                    
                emailext body: "${agEmlBody}",
                to: "${agEmlTo}",
                subject: "${agEmlHdr}"
                from: "JenkinsServer@gmail.com"
            }
        }
    }
    }
}

}

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44362243

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档