Jenkins发送http post请求

我们在使用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'
          }
          }
          
      }
      
    }
    
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容