Jenkinsfile/Groovy: why does eachWithIndex error with "The current scope already contains a variable of the name it"?

I'm trying to replicate this example from the groovy language documentation with the eachWithIndex statement in the following pipeline:

pipeline {
  agent any
  stages {
    stage( "1" ) {
      steps {
        script {
          a = [k1:"v1", k2:"v2"]
          a.eachWithIndex { it, i ->
            echo "${it} ${i}"
          }
        }
      }
    }
  }
}

Why does this generate the following error:

The current scope already contains a variable of the name it


Read more here: https://stackoverflow.com/questions/68477821/jenkinsfile-groovy-why-does-eachwithindex-error-with-the-current-scope-already

Content Attribution

This content was originally published by StoneThrow at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: