This might get you started: https://gist.github.com/kizbitz/e59f95f7557b4bbb8bf2
On Wed, Nov 25, 2020 at 7:58 AM [email protected] <[email protected]> wrote: > I essentially want to get this list, but in a JSON format in an HTTP > response. But using this link as my docker_image_tags_url value for my > script doesn't work of course, that is, it gives a blank list. > > > https://hub.docker.com/r/jenkins/jenkins/tags?page_size=20&page=1&ordering=last_updated > . > > On Wednesday, November 25, 2020 at 9:40:16 AM UTC-5 [email protected] > wrote: > >> I want to use the Groovy script in this post >> <https://kublr.com/blog/advanced-jenkins-groovy-scripting-for-live-fetching-of-docker-images/> >> to get Jenkins versions. So I do this, where I change the >> docker_image_tags_url to point to a Jenkins end point. >> >> // Import the JsonSlurper class to parse Dockerhub API response >> import groovy.json.JsonSlurper >> // Set the URL we want to read from, it is MySQL from official Library >> for this example, limited to 20 results only. >> docker_image_tags_url = " >> https://hub.docker.com/v2/repositories/library/jenkins/tags?page_size=30" >> try { >> // Set requirements for the HTTP GET request, you can add >> Content-Type headers and so on... >> def http_client = new URL(docker_image_tags_url).openConnection() as >> HttpURLConnection >> http_client.setRequestMethod('GET') >> // Run the HTTP request >> http_client.connect() >> // Prepare a variable where we save parsed JSON as a HashMap, it's >> good for our use case, as we just need the 'name' of each tag. >> def dockerhub_response = [:] >> // Check if we got HTTP 200, otherwise exit >> if (http_client.responseCode == 200) { >> dockerhub_response = new >> JsonSlurper().parseText(http_client.inputStream.getText('UTF-8')) >> } else { >> println("HTTP response error") >> System.exit(0) >> } >> // Prepare a List to collect the tag names into >> def image_tag_list = [] >> // Iterate the HashMap of all Tags and grab only their "names" into >> our List >> dockerhub_response.results.each { tag_metadata -> >> image_tag_list.add(tag_metadata.name) >> } >> // The returned value MUST be a Groovy type of List or a related type >> (inherited from List) >> // It is necessary for the Active Choice plugin to display results in >> a combo-box >> return image_tag_list.sort() >> } catch (Exception e) { >> // handle exceptions like timeout, connection errors, etc. >> println(e) >> } >> >> However, it just returns Alpine versions. How can I get the CentOS >> versions? >> >> Thanks, >> Chris >> > -- > You received this message because you are subscribed to the Google Groups > "Jenkins Users" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/jenkinsci-users/365c1f68-145b-499d-a808-bb8b96351386n%40googlegroups.com > <https://groups.google.com/d/msgid/jenkinsci-users/365c1f68-145b-499d-a808-bb8b96351386n%40googlegroups.com?utm_medium=email&utm_source=footer> > . > -- Website: http://earl-of-code.com -- You received this message because you are subscribed to the Google Groups "Jenkins Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/CAPiUgVeiD%3DJGyqKiwiS_bow0QD-kMFQfcOVJ3Rb%3DH37ETwsgJw%40mail.gmail.com.
