Skip to content

Instantly share code, notes, and snippets.

@chrisbelyea
Last active June 22, 2017 22:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrisbelyea/3a37cf20d32a52f0dd9a1639d32a911e to your computer and use it in GitHub Desktop.
Save chrisbelyea/3a37cf20d32a52f0dd9a1639d32a911e to your computer and use it in GitHub Desktop.
Jenkins Active Choices Groovy code to enumerate Git tags
// This snippet enumerates the tags in a GitHub repository and returns them as a java.util.ArrayList
// so they can be used with Jenkins' Active Choices plugin. It doesn't require any additional libraries to be
// loaded.
def tagsUrl = 'http://api.github.com/repos/org/repo/tags' // use the correct GitHub API URL here--this isn't it
def data = new URL(tagsUrl).getText()
def list = new groovy.json.JsonSlurper().parseText(data)
def releases = []
// This is *NOT* idiomatic Groovy, but all of the "proper" ways I found to iterate over the list
// worked in Groovy Console but not within Jenkins' Groovy sandbox. There are just too many poorly
// documented plugins and gotchas inside of Jenkins.
for (i in 0 .. (list.size() -1)) {
releases.add(list[i].name)
}
// The Active Choices plugin just wants you to return a List, Array, or Map
return releases
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment