Jenkinsfile关于httpRequest插件的写法

osc_37817710 发布于 06/24 17:15
阅读 328
收藏 0

开源之夏第三届火热来袭,高校学生参与赢万元奖金!>>>

 

httpRequest httpMode: 'POST', 
			contentType: 'APPLICATION_OCTETSTREAM',           
			formData: [[body: '''{
						 "project_id" : "project",
						 "token" : "1111"
						}''',
		   contentType: 'text/plain', fileName: 'project.exe', name: 'file',
		   uploadFile: 'bin/windows_amd64/111.txt']],
		   responseHandle: 'STRING', timeout: null,
		   url: 'http://xxx/trade/deploy/upload',
		   validResponseCodes: '200,404', validResponseContent: 'token',
		   consoleLogResponseBody: true
 

语法没有报错,但是接口返回“token不能为空”,说明token参数并没有接收到,我该怎么修改写法

上传接口为post请求,参数在body中,类型为form-data,

project: string
token: string
file: file

换官方提供的其他写法也是报"token不能为空"

formData: [
               [contentType: 'multipart/form-data', name: 'token', body: '1111'],
               [contentType: 'multipart/form-data', name: 'project_id', body: '${project_id}'],
               [contentType: 'text/plain', name: 'file', fileName: '${project_id}.exe',
               uploadFile: 'bin/windows_amd64/111.txt']]

参考地址:https://github.com/jenkinsci/http-request-plugin

我尝试把其他表单参数放到地址栏后面http://xxx/trade/deploy/upload?token=111,结果不报token找不到了,但是又有新的问题,服务端接收文件为null......文件在目录下是存在的,路径也没错,如果路径写错会报找不到文件

 

 

加载中
0
osc_37817710
osc_37817710

经调试发现,multipartName属性是接口接收文件的参数名,配对了就可以接收到文件了,不需要配那么多类型的formdata......最终结果如下

httpRequest httpMode: 'POST', 
                            contentType: 'APPLICATION_OCTETSTREAM',	
			                multipartName: 'file',
			                uploadFile: 'bin/111.txt',
                           responseHandle: 'STRING', timeout: null,
                           url: "${upload_path}?token=1111&project_id=${project_id}",
                           validResponseCodes: '200,404', 
                           consoleLogResponseBody: true

 

OSCHINA
登录后可查看更多优质内容
返回顶部
顶部