Jenkins发送HTTP请求

在中国,任何超脱飞扬的思想都会砰然坠地——现实的引力实在是太沉重了。

                          ---《三体》

一、前言

在做集成工作的时候,偶尔需要通过集成工具发送http请求,有好几种方式进行处理,今天记录通过HTTP Request插件和pipline进行处理

二、HTTP Request插件-原料和配件

安装插件HTTP Request

 

 

 

 

三、HTTP Request插件-实现步骤

构建步骤添加HTTP Request

 

 

 

 

 ②可以看到该插件需要填写的参数便是http协议的结构,填写即可

四、HTTP Request插件-测试

构建该任务测试一下,http请求是否发送成功

 

 

 可以看到http请求是发送成功了。

五、pipline实现

 

pipeline {
    agent any

    stages {

        stage('greate') {
            steps {
                
                script {
                            //url
                            def url = 'http://xxx'

                            //请求体
                            def requestBody = '{"requestBody" : "requestBody"}'

                            // 多请求头
                            def headers = [
                                [name: "Content-Type", value: "application/json"],
                                [name: "xxx", value: "xxx"],
                                [name: "xxx", value: "xxx"],
                                [name: "xxx", value: "xxx"]
                            ]

                            //单请求头
                            def customheader = ['Content-Type' : 'application/json']
                            
                            //发送请求
                            def response = httpRequest(
                                contentType: 'APPLICATION_JSON',
                                customHeaders: headers,
                                httpMode: 'POST',
                                requestBody: requestBody,
                                url: url
                            )                   
                }
            }
        }
    }
}

 

posted @ 2023-03-08 16:59  紫陌花间客  阅读(682)  评论(0编辑  收藏  举报