0

I am able to trigger the job but for some reason file is not getting uploaded to the jenkins workspace. If I try that manually from jenkins job runs fine. I have tried below-

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 )

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

Any help is appreciated.

Wilfred Clement
  • 2,674
  • 2
  • 14
  • 29
ashkaps
  • 61
  • 6

1 Answers1

0

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);
Wilfred Clement
  • 2,674
  • 2
  • 14
  • 29
  • Have you tried this code? I am aware how it ideally should work. But this depends on how the api is specified. I am looking for a working solution. Though I have tried this approach too - it does not work. – ashkaps Sep 29 '18 at 10:18
  • Quite surprising, cause this is a working code, not with Jenkins but with a different server – Wilfred Clement Sep 29 '18 at 10:42
  • This is from official docs - curl -X POST JENKINS_URL/job/JOB_NAME/build \ --user USER:PASSWORD \ --form file0=@PATH_TO_FILE \ --form json='{"parameter": [{"name":"FILE_LOCATION_AS_SET_IN_JENKINS", "file":"file0"}]}' I just need a rest assured conversion for this. I have tried this curl and it works. – ashkaps Sep 30 '18 at 09:18