如何上传命令行文件作为詹金斯文件参数(How to upload file from command

2019-07-03 18:32发布

我触发建立从与詹金斯命令行字符串参数:

curl http://jenkins:8080/job/Build/buildWithParameters?PARAM=value&token=token

我现在想用一个文件作为命令行文件参数来触发一个构建。

例如,如果我的项目建立的main.c然后我想能够触发构建和命令行上传我的main.c。

这可能吗?

Answer 1:

这是在描述詹金斯远程访问 API页面:

curl http://jenkins/job/$JOB_NAME/build -F file0=@PATH_TO_FILE -F json='{"parameter": [{"name":"FILE_LOCATION_AS_SET_IN_JENKINS", "file":"file0"}]}'

请注意,您需要使用URL /构建,而不是/ buildWithParameters



Answer 2:

如果您需要两个字符串参数和文件参数发送,您可以执行以下操作:

json='{"parameter": [{"name": "param1", "value": "value1"},
  {"name": "param2", "value": "value2"},
  {"name":"fileParam", "file":"file0"}]}'

url=http://jenkins/job/My_Remote_Jenkins_Job/build

curl -v $url -F file0=@/some/folder/path/template.zip -F json="$json" --user username:password

我必须确保参数param1param2fileParm在詹金斯工作存在My_Remote_Jenkins_Job



Answer 3:

我已经使用(基于使用的Christophers建议将溶液詹金斯-CLI )为:

java -jar jenkins-cli.jar -s http://jenkins:8080 build Build -p main.c=hello.c

与main.c中的文件参数会上传本地的hello.c到Build工作作为main.c中的工作空间



文章来源: How to upload file from command line as file parameter in jenkins