diff --git a/cmd/cloudFoundryDeploy.go b/cmd/cloudFoundryDeploy.go index 4bf7cf40e2..463d640b87 100644 --- a/cmd/cloudFoundryDeploy.go +++ b/cmd/cloudFoundryDeploy.go @@ -428,7 +428,13 @@ func deployMta(config *cloudFoundryDeployOptions, mtarFilePath string, command c cfDeployParams = append(cfDeployParams, deployParams...) } - extFileParams, extFiles := handleMtaExtensionDescriptors(config.MtaExtensionDescriptor) + var extFileParams []string + var extFiles []string + if len(config.MtaExtensionDescriptors) > 0 { + extFileParams, extFiles = handleMtaExtensionDescriptorsAsList(config.MtaExtensionDescriptors) + } else { + extFileParams, extFiles = handleMtaExtensionDescriptors(config.MtaExtensionDescriptor) + } for _, extFile := range extFiles { _, err := fileUtils.Copy(extFile, extFile+".original") @@ -549,10 +555,10 @@ func toMap(keyValue []string, separator string) (map[string]string, error) { return result, nil } -func handleMtaExtensionDescriptors(mtaExtensionDescriptor string) ([]string, []string) { +func handleMtaExtensionDescriptorsAsList(mtaExtensionDescriptors []string) ([]string, []string) { var result = []string{} var extFiles = []string{} - for _, part := range strings.Fields(strings.Trim(mtaExtensionDescriptor, " ")) { + for _, part := range mtaExtensionDescriptors { if part == "-e" || part == "" { continue } @@ -566,6 +572,10 @@ func handleMtaExtensionDescriptors(mtaExtensionDescriptor string) ([]string, []s return result, extFiles } +func handleMtaExtensionDescriptors(mtaExtensionDescriptor string) ([]string, []string) { + return handleMtaExtensionDescriptorsAsList(strings.Fields(strings.Trim(mtaExtensionDescriptor, " "))) +} + func cfDeploy( config *cloudFoundryDeployOptions, cfDeployParams []string, diff --git a/cmd/cloudFoundryDeploy_generated.go b/cmd/cloudFoundryDeploy_generated.go index ab41659673..43f1a6bdec 100644 --- a/cmd/cloudFoundryDeploy_generated.go +++ b/cmd/cloudFoundryDeploy_generated.go @@ -38,6 +38,7 @@ type cloudFoundryDeployOptions struct { ManifestVariablesFiles []string `json:"manifestVariablesFiles,omitempty"` MtaDeployParameters string `json:"mtaDeployParameters,omitempty"` MtaExtensionDescriptor string `json:"mtaExtensionDescriptor,omitempty"` + MtaExtensionDescriptors []string `json:"mtaExtensionDescriptors,omitempty"` MtaExtensionCredentials map[string]interface{} `json:"mtaExtensionCredentials,omitempty"` MtaPath string `json:"mtaPath,omitempty"` Org string `json:"org,omitempty"` @@ -221,7 +222,8 @@ func addCloudFoundryDeployFlags(cmd *cobra.Command, stepConfig *cloudFoundryDepl cmd.Flags().StringSliceVar(&stepConfig.ManifestVariables, "manifestVariables", []string{}, "Defines a list of variables in the form `key=value` which are used for variable substitution within the file given by manifest.") cmd.Flags().StringSliceVar(&stepConfig.ManifestVariablesFiles, "manifestVariablesFiles", []string{`manifest-variables.yml`}, "path(s) of the Yaml file(s) containing the variable values to use as a replacement in the manifest file. The order of the files is relevant in case there are conflicting variable names and values within variable files. In such a case, the values of the last file win.") cmd.Flags().StringVar(&stepConfig.MtaDeployParameters, "mtaDeployParameters", `-f`, "Additional parameters passed to mta deployment command") - cmd.Flags().StringVar(&stepConfig.MtaExtensionDescriptor, "mtaExtensionDescriptor", os.Getenv("PIPER_mtaExtensionDescriptor"), "Defines additional extension descriptor file for deployment with the mtaDeployPlugin") + cmd.Flags().StringVar(&stepConfig.MtaExtensionDescriptor, "mtaExtensionDescriptor", os.Getenv("PIPER_mtaExtensionDescriptor"), "Defines additional extension descriptor file for deployment with the mtaDeployPlugin. Multiple files can be provided as a space separated string.") + cmd.Flags().StringSliceVar(&stepConfig.MtaExtensionDescriptors, "mtaExtensionDescriptors", []string{}, "Defines additional extension descriptor file(s) for deployment with the mtaDeployPlugin provided as a list.") cmd.Flags().StringVar(&stepConfig.MtaPath, "mtaPath", os.Getenv("PIPER_mtaPath"), "Defines the path to *.mtar for deployment with the mtaDeployPlugin") cmd.Flags().StringVar(&stepConfig.Org, "org", os.Getenv("PIPER_org"), "Cloud Foundry target organization.") @@ -458,6 +460,15 @@ func cloudFoundryDeployMetadata() config.StepData { Aliases: []config.Alias{{Name: "cloudFoundry/mtaExtensionDescriptor", Deprecated: true}}, Default: os.Getenv("PIPER_mtaExtensionDescriptor"), }, + { + Name: "mtaExtensionDescriptors", + ResourceRef: []config.ResourceReference{}, + Scope: []string{"PARAMETERS", "STAGES", "STEPS", "GENERAL"}, + Type: "[]string", + Mandatory: false, + Aliases: []config.Alias{}, + Default: []string{}, + }, { Name: "mtaExtensionCredentials", ResourceRef: []config.ResourceReference{}, diff --git a/cmd/cloudFoundryDeploy_test.go b/cmd/cloudFoundryDeploy_test.go index 4558ab835b..6b7bcb788d 100644 --- a/cmd/cloudFoundryDeploy_test.go +++ b/cmd/cloudFoundryDeploy_test.go @@ -939,6 +939,14 @@ func TestExtensionDescriptorsWithMinusE(t *testing.T) { extDesc, _ := handleMtaExtensionDescriptors("") assert.Equal(t, []string{}, extDesc) }) + + t.Run("ExtensionDescriptorsDefinedAsList", func(t *testing.T) { + extDesc, _ := handleMtaExtensionDescriptorsAsList([]string{"1.yaml", "2.yaml"}) + assert.Equal(t, []string{ + "-e", + "1.yaml,2.yaml", + }, extDesc) + }) } func TestAppNameChecks(t *testing.T) { diff --git a/resources/metadata/cloudFoundryDeploy.yaml b/resources/metadata/cloudFoundryDeploy.yaml index c49a5c5a30..bcaafedc5a 100644 --- a/resources/metadata/cloudFoundryDeploy.yaml +++ b/resources/metadata/cloudFoundryDeploy.yaml @@ -274,7 +274,7 @@ spec: default: "-f" - name: mtaExtensionDescriptor type: string - description: "Defines additional extension descriptor file for deployment with the mtaDeployPlugin" + description: "Defines additional extension descriptor file for deployment with the mtaDeployPlugin. Multiple files can be provided as a space separated string." scope: - PARAMETERS - STAGES @@ -284,6 +284,15 @@ spec: aliases: - name: cloudFoundry/mtaExtensionDescriptor deprecated: true + - name: mtaExtensionDescriptors + type: "[]string" + description: "Defines additional extension descriptor file(s) for deployment with the mtaDeployPlugin provided as a list." + scope: + - PARAMETERS + - STAGES + - STEPS + - GENERAL + mandatory: false - name: mtaExtensionCredentials type: "map[string]interface{}" description: "Defines a map of credentials that need to be replaced in the `mtaExtensionDescriptor`. This map needs to be created as `value-to-be-replaced`:`id-of-a-credential-in-jenkins`. The placeholders in the extension descriptor file(s) looks like: `<%= value-to-be-replaced %>`. When used outside Jenkins the secret which corresponds to `id-of-a-credential-in-jenkins` needs to be provided as environment variable in screaming snake case, e.g.: `export ID_OF_A_CREDENTIAL_IN_JENKINS=`. `id-of-a-credential-in-jenkins` needs to be provided in a way so that it can be translated into a valid environment variable name (e.g. don't start with a number). `value-to-be-replaced` must match this regex: `^[-_A-Za-z0-9]+$`."