1

I am using HTTP Request Plugin to make calls to a REST based Web service. In those calls I want to pass the console output URL in request body in JSON format.

I am constructing the console output URL using environment variable ${BUILD_URL}/console.

Environment variable substitution is working for the URL but not for the request body. Any suggestions on code changes that need to be made to the plugin code to make it work. Can someone please share information on how exactly does Jenkins does variable substitution and why it is not working in this case.

Below is the JSON request body:

{'state':'4', 'short_description':'${BUILD_URL}console'}
Gerold Broser
  • 14,080
  • 5
  • 48
  • 107
user55926
  • 315
  • 1
  • 14

1 Answers1

0

I was able to figure out the solution. Tested and confirmed that it's working.

You need to add below line in HttpRequest.java's perform method:

public boolean perform(AbstractBuild<?,?> build, Launcher launcher, BuildListener listener){ throws InterruptedException, IOException
requestBody = evaluate(requestBody, build.getBuildVariableResolver(), envVars);
//rest of the code as it is
}

Just make sure you add line to evaluate requestBody member for presence of environment variables in it before you call performHttpRequest(build, listener, evaluatedUrl, params) method.

Gerold Broser
  • 14,080
  • 5
  • 48
  • 107
user55926
  • 315
  • 1
  • 14