简体   繁体   English

从Jenkins执行cURL

[英]Execute cURL from Jenkins

I'm trying to execute a cURL command from a Jenkins job. 我正在尝试从Jenkins作业执行cURL命令。 Basically I'm trying to retrieve JIRA information using cURL to JIRA REST API and then parse the information using jq. 基本上我正在尝试使用cURL检索JIRA信息到JIRA REST API,然后使用jq解析信息。

I already have a working bat file when ran in command but when call it from the jenkins job I get a 'curl' is not recognized as an internal or external command error even though I can call cURL in any directory since I added it on my Window PATH. 我在运行命令时已经有一个工作的bat文件但是当从jenkins工作调用它时我得到一个'curl'不被识别为内部或外部命令错误,即使我可以在任何目录中调用cURL,因为我将它添加到我的窗口路径。

I tried copying cURL.exe and jq-win64.exe in my Jenkins workspace and don't get any error but the execution doesn't retrieve anything but it does when ran in command prompt. 我尝试在我的Jenkins工作区中复制cURL.exe和jq-win64.exe并且不会收到任何错误,但执行时不会检索任何内容,但在命令提示符下运行时会执行此操作。

Anyone has any idea of what might be the issue? 任何人都知道可能是什么问题? Below is my code: 以下是我的代码:

SET jiraURL="http://localhost:2990/jira/rest/api/2/issue/%1"
SET contentType="Content-Type: application/json"
SET changeSetField=".fields.customfield_10000"
SET devSBField=".fields.customfield_10100"
FOR /f "tokens=*" %%x IN ('curl -u admin:admin -X GET -H %contentType% %jiraURL% ^| jq-win64 %changeSetField%') DO SET changeSetName=%%x
ECHO %changeSetName%
FOR /f "tokens=*" %%y IN ('curl -u admin:admin -X GET -H %contentType% %jiraURL% ^| jq-win64 %devSBField%') DO SET sandboxName=%%y
ECHO %sandboxName%

Note: I know its not efficient to do 2 service call, but will deal with it once I'm done with this error. 注意:我知道进行2次服务调用效率不高,但是一旦我完成此错误就会处理它。 :-) :-)

looks like its a machine thing after all. 毕竟看起来像机器的东西。 I rebooted my machine, ran my local instance of JIRA via command line and then a couple of Java popups asking me about firewall. 我重启了我的机器,通过命令行运行我的本地JIRA实例,然后是几个Java弹出窗口,询问防火墙。

After I set it up I executed my jenkins build again and to my surprise it was able to connect and retrieve the information I needed. 在我设置之后,我再次执行了jenkins构建,令我惊讶的是它能够连接并检索我需要的信息。 i also didn't need to copy cURL.exe and jq-win64.exe to my workspace folder. 我也不需要将cURL.exe和jq-win64.exe复制到我的工作区文件夹中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM