我正在使用CA Service Virtualization,它允许使用特定的POST请求从Swagger文件创建虚拟服务。我正在尝试从jenkins管道执行类似的发布请求,但是当我运行构建时,出现错误消息,提示值丢失。
curl的有效命令是:
curl -X POST "http://localhost:1505/lisa-virtualize-invoke/api/v3/vses/VSE/services" -H "accept: application/json" -H "Content-Type: multipart/form-data" -F "config={"virtualService":{"version":"2","name":"API_Test_22","description":"Invoke API V2","status":""},"transportProtocol":{"typeId":"HTTP","basePath":"/","useGateway":true,"hostHeaderPassThrough":false},"dataProtocol":{"forRequest":true,"typeId":"RESTDPH"}}" -F "deploy=true" -F "inputFile1=@petstore-swagger.json;type=application/json"
为了使curl命令在jenkins管道中运行,我已经进行了很长时间的战斗。
有很多问题 "
个字符。经过多次尝试后,我的构建现在似乎已成功完成,但是缺少值并且未创建虚拟服务。我感到非常绝望,也不知道如何解决。 (下面我使用的是GitHub,而不是本地Swagger文件):
pipeline {
agent { label 'master' }
stages {
stage('build') {
steps {
sh """curl -X POST -H \"authorization: Basic xxx" ""http://10.0.2.2:1505/lisa-virtualize-invoke/api/v3/vses/VSE/services"" -H \"accept: application/json\" -H \"Content-Type: multipart/form-data\" -F ""config={\"virtualService\":{\"version\":\"2\",\"name\":\"API_Test_22\",\"description\":\"Invoke API V2\",\"status\":\"\"},\"transportProtocol\":{\"typeId\":\"HTTP\",\"basePath\":\"/\",\"useGateway\":true,\"hostHeaderPassThrough\":false},\"dataProtocol\":{\"forRequest\":true,\"typeId\":\"RESTDPH\"}}"" -F \"deploy=true\" -F \"fileInput1=https://github.com/marcin-kulik/devttest-test/blob/master/petstore-swagger.json\""""
}
}
}
}
jenkins的输出是:
Started by user Marcin Kulik
Running in Durability level: MAX_SURVIVABILITY
[Pipeline] Start of Pipeline
[Pipeline] node
Running on Jenkins in /var/lib/jenkins/workspace/test-bash-in-pipeline
[Pipeline] {
[Pipeline] stage
[Pipeline] { (build)
[Pipeline] sh
+ curl -X POST -H authorization: Basic bWt1bGlrOm1qc2tleURCQ0g3MzUlXiY= http://10.0.2.2:1505/lisa-virtualize-invoke/api/v3/vses/VSE/services -H accept: application/json -H Content-Type: multipart/form-data -F config={virtualService:{version:2,name:API_Test_22,description:Invoke API V2,status:},transportProtocol:{typeId:HTTP,basePath:/,useGateway:true,hostHeaderPassThrough:false},dataProtocol:{forRequest:true,typeId:RESTDPH}} -F deploy=true -F fileInput1=https://github.com/marcin-kulik/devttest-test/blob/master/petstore-swagger.json
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
100 923 0 293 100 630 559 1202 --:--:-- --:--:-- --:--:-- 1761
{"error":{"type":"JSONException","message":"Missing value. at character 77 of {virtualService:{version:2,name:API_Test_22,description:Invoke API V2,status:},transportProtocol:{typeId:HTTP,basePath:/,useGateway:true,hostHeaderPassThrough:false},dataProtocol:{forRequest:true,typeId:RESTDPH}}"}}[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
Finished: SUCCESS
答案 0 :(得分:1)
好像不接受空的“状态”值。
您需要删除此密钥。
答案 1 :(得分:1)
对于双引号问题,请尝试将其与简单引号混合使用,这样可以缓解问题。
pipeline {
agent { label 'master' }
stages {
stage('build') {
steps {
sh 'curl -X POST -H "authorization: Basic xxx" "http://0.0.0.0/lisa-virtualize-invoke/api/v3/vses/VSE/services" -H "accept: application/json" -H "Content-Type: multipart/form-data" -F \'config={"virtualService":{"version":"2","name":"API_Test_22","description":"Invoke API V2","status":""},"transportProtocol":{"typeId":"HTTP","basePath":"/","useGateway":true,"hostHeaderPassThrough":false},"dataProtocol":{"forRequest":true,"typeId":"RESTDPH"}}\' -F "deploy=true" -F "fileInput1=https://github.com/marcin-kulik/devttest-test/blob/master/petstore-swagger.json"'
}
}
}
}
无论如何,对于您的错误,状态字段似乎不允许为空值。