Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Using array in Jenkins curl request

I have a Jenkins job (scripted pipeline) which have curl request inside "sh" block. This is an API call to Github organization, I need to use it for some repositories (about 15) in this organization. I can create 15 lines of curl requests, but I wonder if it’s possible to pass repositories as arrays and add maybe a loop. Something like this:

def REPOS = [‘repo1’, ‘repo2’]
sh
"""
curl -d "mydata" -X POST ‘www.website/api/{REPOS}’
"""

But I don’t understand how to make it work with array and loop considering that I have Groovy + sh + curl

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

This will work for you.

steps {
    script {
      def repos = ['repo1', 'repo2']
      repos.each() {
      sh """ 
       echo $it
       echo "CURl here for ${it}"
       curl -d "mydata" -X POST 'https://www.website/api/${it}' 
      """
      }
    }

  }
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading