简体   繁体   English

使用restassured远程构建具有文件参数的jenkins作业

[英]Remotely build jenkins job with file parameters using restassured

I am able to trigger the job but for some reason file is not getting uploaded to the jenkins workspace. 我能够触发作业,但是由于某种原因文件没有上传到jenkins工作区。 If I try that manually from jenkins job runs fine. 如果我尝试从jenkins手动运行,则运行正常。 I have tried below- 我在下面尝试过-

1 ) 1)

RestAssured.given()
.auth().basic("USERNAME", "PASSWORD")
//.contentType(ContentType.URLENC)
.when()
.post("https://JENKINS_HOST/hudson/job/RISTSA/job/JOB_NAME/buildWithParameters" + "?file=C:/PATH_TO_FILE/SOMETHING.json&JenkinsStringParamName=test")
.then()
.statusCode(201);

2 ) 2)

RestAssured.given().log().all()
.contentType(ContentType.URLENC)
.auth().basic("USERNAME", "PASSWORD")
//.headers(httpHeaders("USERNAME", "PASSWORD"))
.formParam("file0", "C:/PATH_TO_FILE/SOMETHING.json")
.formParam("json", "{\"parameter\":[{\"name\":\"JenkinsFileParamName\",\"file\":\"file0\"},{\"name\":\JenkinsStringParamName\",\"value\":\"test\"}]}")
.when()
.post("https://JENKINS_HOST/hudson/job/RISTSA/job/JOB_NAME/buildWithParameters")
.then()
.statusCode(201);

I have tried to write this code from the official url which has a curl reference on jenkins docs 我试图从官方网址编写此代码,该网址在jenkins文档上有curl引用

Any help is appreciated. 任何帮助表示赞赏。

If you are uploading a file then you are supposed to use multipart 如果要上传文件,则应该使用多部分

RestAssured.given().
multiPart("file2", new File("C:/PATH_TO_FILE/SOMETHING.json")).
formParam("name", "value").
when().
post("https://JENKINS_HOST/hudson/job/RISTSA/job/JOB_NAME/buildWithParameters").
then().
statusCode(201);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM