简体   繁体   English

当我的脚本运行的节点是 jenkins 管道脚本时,如何调用 REST API 管道脚本?

[英]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.

相关问题 从Windows运行时,为什么我的Perl脚本找不到文件? - Why can't my Perl script find the file when I run it from Windows? 如何从 node.js 运行 Python 脚本 - How to run Python Script from node js 如何从Windows中的脚本运行不同的项目? - How can I run different projects from a script in windows? 如何在不结束的情况下从另一个批处理脚本调用一个批处理脚本? - How can I call a batch script from another batch script without pausing at the end? 通过任务计划程序运行.bat脚本时,如何防止显示cmd.exe窗口? - How can I prevent a cmd.exe window from showing when a .bat script is run via Task Scheduler? 如何使Python脚本成为系统命令并在Windows中的任何目录中轻松运行? - How can I make my Python script a system command and run it easily in any directory in Windows? 我如何优化在不同操作系统上运行的 web 抓取脚本 - how can i optimize my web Scraping script run on deferent OS 执行批处理脚本在 Jenkins 管道作业中不起作用 - Execute Batch Script not working in Jenkins Pipeline Job 如何判断 Perl 脚本是在控制台上运行还是在 Windows 计划任务上运行? - How can I tell when a Perl script is run on the console vs a Windows Scheduled Task? 当Shell不完全交互时,如何使用Powershel以其他用户身份登录或以其他用户身份运行脚本? - How can i use powershel to login as another user or run a script as another user when the shell is not fully interactive?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM