[英]How can I call a REST API from jenkins pipeline script when the node my script run is?
In jenkins pipeline script, I need to write script for following steps:在 jenkins 管道脚本中,我需要为以下步骤编写脚本:
Call a REST API and get the key value returned by it调用一个 REST API 得到它返回的键值
Use that key value to call another end point of that REST API.使用该键值调用该 REST API 的另一个端点。
The nodes I have in Jenkins are Windows machines.我在 Jenkins 中拥有的节点是 Windows 机器。 So I need a script which can run in Windows.所以我需要一个可以在 Windows 中运行的脚本。
You can install the "curl" on your windows nodes and then call the API using curl command, please refer the below:-您可以在 windows 节点上安装“curl”,然后使用 curl 命令调用 API,请参阅以下内容:-
def API = "curl -X GET API"
def apiKey = bat (script: API, returnStdout: true)
NOTE - " bat " will execute it as batch script on windows node注意- “ bat ”将在 windows 节点上作为批处理脚本执行
The " apiKey " will contain the value returned by the API, which you can use for calling other API “ apiKey ” 将包含 API 返回的值,您可以使用它来调用其他 API
You can also use the httpRequest plugin in jenkins,也可以使用jenkins中的httpRequest插件,
def response = httpRequest 'http://localhost:8080/jenkins/api/json?pretty=true'
println("Status: "+response.status)
println("Content: "+response.content)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.