Jenkins打包android项目构建成功后发送http-post请求

这篇文章主要记录Jenkins自动化打包android项目后使用http-request插件发送post请求的记录

1.安装http-request插件,步骤如下:
  插件下载地址:http://updates.jenkins-ci.org/download/plugins/
  搜索选择http_request下载到本地,然后按照下面的截图上传并安装插件
      
  系统管理-->插件管理-->选择高级-->上传插件
  上传成功后最好重启一下Jenkins,浏览器输入:http://xx.xx.xx.xx:8080/restart 回车确认即可重启。到这插件安装完成。接下来就是创建pipeline的步骤了。
2.编写pipeline流水线脚本  
     
   新建任务-->输入名称-->选择流水线-->确定

   Jenkins-->我的视图-->项目列表,即可看到所有项目,包括刚才创建的pipeline流水线.
   选择刚才创建的pipeline-->点击配置进入配置页面,下面就是在配置页面进行操作了。
      

def response = httpRequest contentType: 'APPLICATION_JSON',
        httpMode: "POST",
        customHeaders: [
          [name: "token", value: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9uxHjaqt-hI"]
        ],
        url: "https://xxx.com/message?is_room=true&type=1&content=Android最新安装包:http://xx.xx.xx.xx:8080/job/Android/lastSuccessfulBuild/artifact/app/build/outputs/apk/"
println response.status
println response.content

//具体httpRequest参数请参考:https://www.jenkins.io/doc/pipeline/steps/http_request/#httprequest-perform-an-http-request-and-return-a-response-object

 

原文地址:https://www.cnblogs.com/yongfengnice/p/13582253.html