我在控制台发送 curl 命令如下
curl -v http://124.205.41.149:8080/jenkins/job/pinpoint_single_machine_scan/build -F file0=@@/home/git/gitlab/public/uploads/topinpoint.zip -F json='{"parameter": [{"name":"PP_PRECISION","value": "normal"},{"name": "PP_JAVA_MODE", "value": "jar"},{"name": "PP_PROJECT_NAME", "value": "thirdpipeline1"},{"name":"upload/project.zip", "file":"file0"}]}' --user admin:1243758e195b1073e663144699134375d9
我想在 ruby 代码中实现,最终采用了 rest-client,我的代码如下,试了很多次,主要是下面两种,参数一直在调
response = RestClient::Request.execute(
:method => :post,
:url => 'http://124.205.41.149:8080/jenkins/job/pinpoint_single_machine_scan/build',
:user => 'admin',
:password => '1243758e195b1073e663144699134375d9',
:payload => {
:multipart => true,
:file => File.new("#{Rails.root}/public/uploads/topinpoint.zip", 'rb'),
:parameter => [
{"name" => "PP_PRECISION"," value" => "normal"},
{"name" => "PP_JAVA_MODE", "value" => "jar"},
{"name" => "PP_PROJECT_NAME", "value" => "thirdpipeline1"},
{"name" => "upload/project.zip", "file" => "file0"}
]
}
)
RestClient.post('http://124.205.41.149:8080/jenkins/job/pinpoint_single_machine_scan/build',
{
:user => 'admin',
:password => '1243758e195b1073e663144699134375d9',
:parameter => [
{"name" => "PP_PRECISION"," value" => "normal"},
{"name" => "PP_JAVA_MODE", "value" => "jar"},
{"name" => "PP_PROJECT_NAME", "value" => "thirdpipeline1"},
{"name" => "upload/project.zip", "file" => "file0"}
],
:upload => {
:file => File.new("#{Rails.root}/public/uploads/topinpoint.zip", 'rb')
}
})
感觉是自己写法有问题,因为我的curl
中既有附件,还有参数数组,求解,折腾了好久,特来请教,先谢谢大家了🙏