Using 3rd Party APIs with Active Choices plugin

Issue

  • I want to be able to use an external API with the Active Choices plugin

Environment

  • CloudBees Jenkins Enterprise
  • Active Choices Plugin

Resolution

def testAPICall= new testAPICall()
def project = null
def default_list = ["DEFAULT:selected"]
try{
project = testAPICall.getProject($PROJECT_NAME)
} catch(Exception e) {
return default_list
}
def suite_list = []
suite_list.add("DEFAULT:selected")
if (project != null) {
def suites = testAPICall.findTestSuites(Long.parseLong(project.getId()))
def suite_id = ""
def suite_name = ""
for(suite in suites) {
suite_id = String.valueOf(suite.get("id"));
suite_name = String.valueOf(suite.get("name"));
suite_list.add(String.format("%s:%s", suite_name, suite_id ))
}
}
return (suite_list.size() == 0 ? default_list : suite_list)

This code goes out to your API to grab a set of suites and adds them to the slectable lists. If that fails then it just returns the default list you setup with the Active Choices plugin.

Make sure to have the try/catch block so that when it fails it fails correctly

Have more questions? Submit a request

0 Comments

Please sign in to leave a comment.