I’ve function like the following
def runTestsInDocker(arg) {
measureDuration(script: this, measurementName: 'build') {
executeDocker(dockerImage: dockerImage, dockerWorkspace: '/go/src') {
sh """
mkdir -p /go/src/github.com/ftr/myGoPro
go ${arg}
"""
}
}
When I’ve only 1 parameter this is working as expected Now I want to add new parameters so I can do something like this
def runTestsInDocker(arg,arg2,arg3) {
measureDuration(script: this, measurementName: 'build') {
executeDocker(dockerImage: dockerImage, dockerWorkspace: '/go/src') {
sh """
mkdir -p /go/src/github.com/ftr/myGoPro
go ${arg}
go ${arg1}
go ${arg2}
"""
}
}
But here I’ve two problems
1 . What happen if I need to pass only one parameter?
- If I’ve 10 parameters to pass I will have 10 args?
Is there a nicer way in groovy to handle it ?
update , let's say I need to call to the function with 1 parameters
def runTestsInDocker(Map<String,String> params) {
measureDuration(script: this, measurementName: 'build') {
executeDocker(dockerImage: dockerImage, dockerWorkspace: '/go/src') {
sh """
mkdir -p /go/src/github.com/ftr/myGoPro
go ${params.get('arg')}
"""
}
}
And other function
def runTestsInDocker(Map<String,String> params) {
measureDuration(script: this, measurementName: 'build') {
executeDocker(dockerImage: dockerImage, dockerWorkspace: '/go/src') {
sh """
mkdir -p /go/src/github.com/ftr/myGoPro
go ${params.get('arg')}
go ${params.get('arg1')}
"""
}
}
I don't know in advance how much parameters I will need to use, so how can I do it dynamically ?