如何上传文件到jenkins,并使用它来构建? [英] How to upload file to jenkins and use it for build?

查看:10025
本文介绍了如何上传文件到jenkins,并使用它来构建?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Jenkins的新手,我一直在尝试使用curl来创建我的工作。除了这个curl,我想发送一个文件到Jenkins,应该放在我的工作区的特定目录。我一直在搜索,但似乎找不到可以导致我解决方案的明确文件。请指导。我看了一些关于谷歌和StackOverflow的其他文章,但没有找到我要找的。


curl -X POST JENKINS_URL / job / JOB_NAME / build \
--form file0 = / home / abc.xml \
--form json ='{parameter:[{name:/ workspace,file:file0}]}'


解决方案

我已经尝试过了,来自Jenkins文件参数帮助


指定在工作空间中相对的位置,上传的
文件将放在哪里,例如jaxb-ri / data.zip)


上传的文件位置是相对于工作区。 您需要在脚本中复制/移动它。名称部分是作业的文件参数名称。它不是您的文件的名称



这里是从脚本。作业具有名为RECORDS_LIST的文件参数。

  curl -X POST http:// localhost:8080 / job / builder / build \ 
--form attachedfile = @ c:/1.txt \
--form json ='{parameter:[{name:RECORDS_LIST,file:attachedfile}]}'

您可以

  curl -X POST JENKINS_URL / job / JOB_NAME / build \ 
--form file0 = / home / abc.xml \
--form json ='{parameter:[{ name:YOUR_JOBS_FILE_ARGUMENT_NAME,file:file0}]}'

jenkins 命令行api 可以处理文件上传

  java -jar jenkins-cli.jar -s http:// localhost:8080 / build builder \ 
-p YOUR_JOBS_FILE_ARGUMENT_NAME = / home /abc.xml

[在看到OP自己的回答后编辑]



警告



curl命令中的文件名路径部分为'@'(注意@ before path)。 jenkins cli不需要它。这个错误发生时很难跟踪。


I am very new to Jenkins, and I have been trying to use curl to build my job. Along with this curl I want to send a file to Jenkins which should be placed in particular directory of my workspace. I have been googling alot, but could not seem to find clear documentation that could lead me to solution. Please Guide. I looked at some other articles on Google and StackOverflow as well, but couldn't find what I am looking for.

curl -X POST JENKINS_URL/job/JOB_NAME/build \ --form file0=/home/abc.xml \ --form json='{"parameter": [{"name":"/workspace", "file":"file0"}]}'

I tried this as well, didn't seem to work.

解决方案

From Jenkins file parameter help

Specifies the location, relative in the workspace, where the uploaded file will be placed (for example, like "jaxb-ri/data.zip")

The uploaded file location is relative to workspace. You need to copy/move it in a script. The name portion is job's file argument's name. It is not name of your file

Here is from script. The job has a file parameter named RECORDS_LIST.

curl -X POST  http://localhost:8080/job/builder/build \
             --form attachedfile=@c:/1.txt \
             --form json='{"parameter": [{"name":"RECORDS_LIST", "file":"attachedfile"}]}'

Yours could be

curl -X POST JENKINS_URL/job/JOB_NAME/build \ 
  --form file0=/home/abc.xml \ 
  --form json='{"parameter": [{"name":"YOUR_JOBS_FILE_ARGUMENT_NAME", "file":"file0"}]}'

Please note that jenkins command line api can handle file upload

java -jar jenkins-cli.jar -s http://localhost:8080/ build builder \
      -p YOUR_JOBS_FILE_ARGUMENT_NAME=/home/abc.xml

[edit after seeing OP's own answer]

Alert

The filename path part in curl command has '@' (note that @ before path) . The jenkins cli does not need it. This error, when happens, is difficult to track.

这篇关于如何上传文件到jenkins,并使用它来构建?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆