Jenkins – How to Use For Loop in Declarative Pipeline

Jenkins

I am having a list of variable like below

allModules = ['module1', 'module2', 'module3', 'module4', 'module11']

I want to use loop then print all the module one by one.

Please let me know the syntax and how to perform this in Jenkins Declarative pipeline

Best Answer

Pure declarative pipelines don't support loops. Use a script step. There's actually an example on that page that does exactly what you want.

A more readable and concise (IMO) solution would use iterators, like so:

steps {
   script {
      allModules.each() {
         echo it
      }
   }
}