Hello,
I am using map to set additional arguments when calling a function for example:
def build_test_lambda(Map config) {
dir (config.src_path) {
script {
def ROLE_CODE = config.role_code
def BRANCH = env.GIT_BRANCH.replaceAll("/", "-").replaceAll(" ", "_")
def package_name = "${config.lambda_name}-${BRANCH}-${currentBuild.number}.zip"
def version = currentBuild.number
if (env.GIT_BRANCH == 'master') {
def packageJson = readJSON file: "${WORKSPACE}/package.json"
sh "echo Lambda: '${config.lambda_name}'. Version: '${packageJson.version}'"
version = "'${packageJson.version}'"
package_name = "${config.lambda_name}-${BRANCH}-${packageJson.version}.zip"
}
}
When I call the function I have to provide all arguments as follows:
build_test_lambda(lambda_name: "apihttptestlambda", dockerFileName: "TestLambda/Dockerfile", role_code: "TEST_LAMBDA", src_path: "app/src", app_code: TEST_APP_CODE)
Is there a way to define a default values for let say config.src_path and if not specified in the function call statement to use the default values, otherwise if it’s specified to use the argument provided in the call function?
The idea is to be able to call the function only with one argument for example and to not throw an error:
build_test_lambda(dockerFileName: "TestLambda/Dockerfile")
I am little bit new to programming and especially Groovy
So I hope some would be able to help me, thanks!