美文网首页自动化运维
Jenkins发送http post请求

Jenkins发送http post请求

作者: 褪色的记忆1994 | 来源:发表于2019-10-22 14:41 被阅读0次

    我们在使用jenkins时,可能会遇到需要发送http请求的情况,我们通常使用curl通过执行shell命令的方式来发送http,但这会遇到一些其他问题,这里介绍jenkins原生的一种方式。

    1. 第一步先安装Http Request插件
      在插件中心安装Http Request插件即可进行安装
    2. 编写Jenkinsfile
    import groovy.json.JsonSlurper
    
    pipeline{
        agent {
            node {
                label 'master'
            }
        }
        stages{
          stage('http') {
              steps {
                script {
                  def toJson = {
                    input ->
                    groovy.json.JsonOutput.toJson(input)
                }
                def body = [
                    status: "DOWN"
                ]
                def unregister_url= "http://localhost:8896/actuator/service-registry"
                response = httpRequest consoleLogResponseBody: true, contentType: 'APPLICATION_JSON', httpMode: 'POST', requestBody: toJson(body), url: unregister_url, validResponseCodes: '200'
              }
              }
              
          }
          
        }
        
    }
    

    相关文章

      网友评论

        本文标题:Jenkins发送http post请求

        本文链接:https://www.haomeiwen.com/subject/mquqvctx.html