Skip to content

Instantly share code, notes, and snippets.

@imeanitworks
Created May 7, 2019 23:10
Show Gist options
  • Select an option

  • Save imeanitworks/18989554090e15d6dd52c7af15201001 to your computer and use it in GitHub Desktop.

Select an option

Save imeanitworks/18989554090e15d6dd52c7af15201001 to your computer and use it in GitHub Desktop.
Groovy for loop
#!/bin/groovy
pipeline {
agent { label 'label' }
define {
def my_map = [:] //empty map
def my_list //undefined shared variable
}
stages {
stage('stage1') {
steps {
script {
//If def can be anywhere in pipeline {}, drop script {}
my_list = [1,2,3]
}
}
}
stage('stage2') {
steps {
script {
for(int i=0; i<my_list.size();i++) {
echo "Doing something with ${my_list[i]}"
}
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment