Jenkins Dynamic Parameters - List of Application Versions from Artifactory
The below code lists All Versions Built for an application from the artifactory.
import groovy.json.JsonSlurper
try {
def appName=binding.variables.get('<appName>')
def appPrefix=binding.variables.get('<appPrefix>')
List<String> artifacts = new ArrayList<String>()
def artifactsUrl = "https://artifactory.corp.com/release-local/data-items/"+appPrefix+"-"+appName+"/1.0/"+appPrefix+"-"+appName+"-1.0.json"
def artifactsObjectRaw = ["curl", "-s", "-H", "accept: application/json", "-k", "--url", "${artifactsUrl}"].execute().text
def jsonSlurper = new JsonSlurper()
def artifactsJsonObject = jsonSlurper.parseText(artifactsObjectRaw)
def dataArray = artifactsJsonObject.data
for(item in dataArray){
if (item.isMetadata== false)
artifacts.add(item.version)
}
return artifacts
} catch (Exception e) {
print "There was a problem fetching the artifacts"
}
Steps:
1. In your Jenkins build job run the below command as a post steps to upload the versions to a json file.
java GetArtifactoryVersions <appName>
Note: GetArtifactoryVersions code link https://infradmins.blogspot.com/2019/04/getartifactoryversions.html.
2. In your Jenkins Deployment Job add a Active Choices Reactive Parameter with the Groovy script given above
Comments
Post a Comment