這篇文章主要記錄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