I have a map of data that I have extracted during a Groovy pipeline script. In the next stage of the pipeline I would like to loop through the data and insert in the environmental variables for usage.
This stage includes a ant command that uses a build xml to retrieve the environmental ${env.appName} parameter.
(see xml example below)
<project ...>
...
<entry ...value="${env.appName}/>
<entry ...value="${env.version}/>
...
</project>
I am going through the key value pair of the map.
pipeline {
agent any
stages{
stage ('Data') {
steps{
scripts {
def map = [app1: "01.01", app2: "02.02"]
}
}
}
stage ('Loop'){
steps {
withAnt(){
sh '''
{map.collect{ k,v -> "appName=${k} version=${v}"}}
ant -buildfile ~/build.xml
...
'''
}
}
}
}
}
However, I get an error:
line 3 : {map.collect{ k,v -> "appName=${k} version=${v}"}}: bad substitution.
Is it possible to loop a map in the sh block?
Is there a way to do this so that the ant command is done on each element of the map?
sh. Then use"""instead of'''to have replacement. - cfrick