Given: The external web service that has an endpoind /info.

GET request returns JSON like this:

{
  "displayName":"Info Service",
  "version":"961-830ae2c9",
  ...
}

In a Jenkins job when it’s triggered we need to get the value of the version and dynamically set it as a parameter VERSION for the build.

Jenkins extended choice parameter

Jenkins Extended Choice Parameter

Make the Jenkins job parameterized by checking This project is parameterized.

Add Extended Choice Parameter and set that as shown below

Jenkins Extended Choice Parameter

Groovy Script

This is the Groovy Script from the picture

def version = new groovy.json.JsonSlurper().parse(new URL("https://test.xxxx.com/info")).version
return [version]

Now you can use the parameter VERSION just like this ${VERSION}


You may also find these posts interesting: