mirror of
https://github.com/SAP/jenkins-library.git
synced 2025-01-18 05:18:24 +02:00
Add optional wrapper for cloudFoundryDeploy go-implementation (#1952)
Co-authored-by: Kevin Hudemann <kevin.hudemann@sap.com>
This commit is contained in:
parent
f6f85342b7
commit
46284d8f34
@ -80,6 +80,8 @@ func runCloudFoundryDeploy(config *cloudFoundryDeployOptions, telemetryData *tel
|
||||
return err
|
||||
}
|
||||
|
||||
validateDeployTool(config)
|
||||
|
||||
var deployTriggered bool
|
||||
|
||||
if config.DeployTool == "mtaDeployPlugin" {
|
||||
@ -99,6 +101,21 @@ func runCloudFoundryDeploy(config *cloudFoundryDeployOptions, telemetryData *tel
|
||||
return err
|
||||
}
|
||||
|
||||
func validateDeployTool(config *cloudFoundryDeployOptions) {
|
||||
if config.DeployTool != "" || config.BuildTool == "" {
|
||||
return
|
||||
}
|
||||
|
||||
switch config.BuildTool {
|
||||
case "mta":
|
||||
config.DeployTool = "mtaDeployPlugin"
|
||||
default:
|
||||
config.DeployTool = "cf_native"
|
||||
}
|
||||
log.Entry().Infof("Parameter deployTool not specified - deriving from buildTool '%s': '%s'",
|
||||
config.BuildTool, config.DeployTool)
|
||||
}
|
||||
|
||||
func validateAppName(appName string) error {
|
||||
// for the sake of brevity we consider the empty string as valid app name here
|
||||
isValidAppName, err := regexp.MatchString("^$|^[a-zA-Z0-9]$|^[a-zA-Z0-9][a-zA-Z0-9-]*[a-zA-Z0-9]$", appName)
|
||||
|
@ -24,6 +24,7 @@ type cloudFoundryDeployOptions struct {
|
||||
CfPluginHome string `json:"cfPluginHome,omitempty"`
|
||||
DeployDockerImage string `json:"deployDockerImage,omitempty"`
|
||||
DeployTool string `json:"deployTool,omitempty"`
|
||||
BuildTool string `json:"buildTool,omitempty"`
|
||||
DeployType string `json:"deployType,omitempty"`
|
||||
DockerPassword string `json:"dockerPassword,omitempty"`
|
||||
DockerUsername string `json:"dockerUsername,omitempty"`
|
||||
@ -92,7 +93,7 @@ func (i *cloudFoundryDeployInflux) persist(path, resourceName string) {
|
||||
}
|
||||
}
|
||||
|
||||
// CloudFoundryDeployCommand Deploys an application to cloud foundry
|
||||
// CloudFoundryDeployCommand Deploys an application to Cloud Foundry
|
||||
func CloudFoundryDeployCommand() *cobra.Command {
|
||||
const STEP_NAME = "cloudFoundryDeploy"
|
||||
|
||||
@ -103,7 +104,7 @@ func CloudFoundryDeployCommand() *cobra.Command {
|
||||
|
||||
var createCloudFoundryDeployCmd = &cobra.Command{
|
||||
Use: STEP_NAME,
|
||||
Short: "Deploys an application to cloud foundry",
|
||||
Short: "Deploys an application to Cloud Foundry",
|
||||
Long: `Deploys an application to a test or production space within Cloud Foundry.`,
|
||||
PreRunE: func(cmd *cobra.Command, _ []string) error {
|
||||
startTime = time.Now()
|
||||
@ -160,11 +161,12 @@ func addCloudFoundryDeployFlags(cmd *cobra.Command, stepConfig *cloudFoundryDepl
|
||||
cmd.Flags().StringVar(&stepConfig.CfPluginHome, "cfPluginHome", os.Getenv("PIPER_cfPluginHome"), "The cf plugin home folder used by the cf cli. If not provided the default assumed by the cf cli is used.")
|
||||
cmd.Flags().StringVar(&stepConfig.DeployDockerImage, "deployDockerImage", os.Getenv("PIPER_deployDockerImage"), "Docker image deployments are supported (via manifest file in general)[https://docs.cloudfoundry.org/devguide/deploy-apps/manifest-attributes.html#docker]. If no manifest is used, this parameter defines the image to be deployed. The specified name of the image is passed to the `--docker-image` parameter of the cf CLI and must adhere it's naming pattern (e.g. REPO/IMAGE:TAG). See (cf CLI documentation)[https://docs.cloudfoundry.org/devguide/deploy-apps/push-docker.html] for details. Note: The used Docker registry must be visible for the targeted Cloud Foundry instance.")
|
||||
cmd.Flags().StringVar(&stepConfig.DeployTool, "deployTool", os.Getenv("PIPER_deployTool"), "Defines the tool which should be used for deployment.")
|
||||
cmd.Flags().StringVar(&stepConfig.BuildTool, "buildTool", os.Getenv("PIPER_buildTool"), "Defines the tool which is used for building the artifact. If provided, `deployTool` is automatically derived from it. For MTA projects, `deployTool` defaults to `mtaDeployPlugin`. For other projects `cf_native` will be used.")
|
||||
cmd.Flags().StringVar(&stepConfig.DeployType, "deployType", `standard`, "Defines the type of deployment, either `standard` deployment which results in a system downtime or a zero-downtime `blue-green` deployment.If 'cf_native' as deployType and 'blue-green' as deployTool is used in combination, your manifest.yaml may only contain one application. If this application has the option 'no-route' active the deployType will be changed to 'standard'.")
|
||||
cmd.Flags().StringVar(&stepConfig.DockerPassword, "dockerPassword", os.Getenv("PIPER_dockerPassword"), "dockerPassword")
|
||||
cmd.Flags().StringVar(&stepConfig.DockerUsername, "dockerUsername", os.Getenv("PIPER_dockerUsername"), "dockerUserName")
|
||||
cmd.Flags().StringVar(&stepConfig.DockerPassword, "dockerPassword", os.Getenv("PIPER_dockerPassword"), "If the specified image in `deployDockerImage` is contained in a Docker registry, which requires authorization, this defines the password to be used.")
|
||||
cmd.Flags().StringVar(&stepConfig.DockerUsername, "dockerUsername", os.Getenv("PIPER_dockerUsername"), "If the specified image in `deployDockerImage` is contained in a Docker registry, which requires authorization, this defines the username to be used.")
|
||||
cmd.Flags().BoolVar(&stepConfig.KeepOldInstance, "keepOldInstance", false, "In case of a `blue-green` deployment the old instance will be deleted by default. If this option is set to true the old instance will remain stopped in the Cloud Foundry space.")
|
||||
cmd.Flags().StringVar(&stepConfig.LoginParameters, "loginParameters", os.Getenv("PIPER_loginParameters"), "Addition command line options for cf login command. No escaping/quoting is performed. Not recommanded for productive environments.")
|
||||
cmd.Flags().StringVar(&stepConfig.LoginParameters, "loginParameters", os.Getenv("PIPER_loginParameters"), "Addition command line options for cf login command. No escaping/quoting is performed. Not recommended for productive environments.")
|
||||
cmd.Flags().StringVar(&stepConfig.Manifest, "manifest", os.Getenv("PIPER_manifest"), "Defines the manifest to be used for deployment to Cloud Foundry.")
|
||||
cmd.Flags().StringSliceVar(&stepConfig.ManifestVariables, "manifestVariables", []string{}, "Defines a list of variables as key-value Map objects used for variable substitution within the file given by manifest. Defaults to an empty list, if not specified otherwise. This can be used to set variables like it is provided by 'cf push --var key=value'. The order of the maps of variables given in the list is relevant in case there are conflicting variable names and value between maps contained within the list. In case of conflicts, the last specified map in the list will win. Though each map entry in the list can contain more than one key-value pair for variable substitution, it is recommended to stick to one entry per map, and rather declare more maps within the list. The reason is that if a map in the list contains more than one key-value entry, and the entries are conflicting, the conflict resolution behavior is undefined (since map entries have no sequence). Note: variables defined via 'manifestVariables' always win over conflicting variables defined via any file given by 'manifestVariablesFiles' - no matter what is declared before. This is the same behavior as can be observed when using 'cf push --var' in combination with 'cf push --vars-file'.")
|
||||
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.")
|
||||
@ -179,7 +181,6 @@ func addCloudFoundryDeployFlags(cmd *cobra.Command, stepConfig *cloudFoundryDepl
|
||||
cmd.Flags().StringVar(&stepConfig.Username, "username", os.Getenv("PIPER_username"), "User")
|
||||
|
||||
cmd.MarkFlagRequired("apiEndpoint")
|
||||
cmd.MarkFlagRequired("deployTool")
|
||||
cmd.MarkFlagRequired("org")
|
||||
cmd.MarkFlagRequired("password")
|
||||
cmd.MarkFlagRequired("space")
|
||||
@ -199,7 +200,7 @@ func cloudFoundryDeployMetadata() config.StepData {
|
||||
{
|
||||
Name: "apiEndpoint",
|
||||
ResourceRef: []config.ResourceReference{},
|
||||
Scope: []string{"PARAMETERS", "STAGES", "STEPS"},
|
||||
Scope: []string{"PARAMETERS", "STAGES", "STEPS", "GENERAL"},
|
||||
Type: "string",
|
||||
Mandatory: true,
|
||||
Aliases: []config.Alias{{Name: "cfApiEndpoint"}, {Name: "cloudFoundry/apiEndpoint"}},
|
||||
@ -207,7 +208,7 @@ func cloudFoundryDeployMetadata() config.StepData {
|
||||
{
|
||||
Name: "appName",
|
||||
ResourceRef: []config.ResourceReference{},
|
||||
Scope: []string{"PARAMETERS", "STAGES", "STEPS"},
|
||||
Scope: []string{"PARAMETERS", "STAGES", "STEPS", "GENERAL"},
|
||||
Type: "string",
|
||||
Mandatory: false,
|
||||
Aliases: []config.Alias{{Name: "cfAppName"}, {Name: "cloudFoundry/appName"}},
|
||||
@ -215,7 +216,7 @@ func cloudFoundryDeployMetadata() config.StepData {
|
||||
{
|
||||
Name: "artifactVersion",
|
||||
ResourceRef: []config.ResourceReference{{Name: "commonPipelineEnvironment", Param: "artifactVersion"}},
|
||||
Scope: []string{"PARAMETERS", "STAGES", "STEPS"},
|
||||
Scope: []string{"PARAMETERS", "STAGES", "STEPS", "GENERAL"},
|
||||
Type: "string",
|
||||
Mandatory: false,
|
||||
Aliases: []config.Alias{},
|
||||
@ -223,7 +224,7 @@ func cloudFoundryDeployMetadata() config.StepData {
|
||||
{
|
||||
Name: "cfHome",
|
||||
ResourceRef: []config.ResourceReference{},
|
||||
Scope: []string{"PARAMETERS", "STAGES", "STEPS"},
|
||||
Scope: []string{"PARAMETERS", "STAGES", "STEPS", "GENERAL"},
|
||||
Type: "string",
|
||||
Mandatory: false,
|
||||
Aliases: []config.Alias{},
|
||||
@ -231,7 +232,7 @@ func cloudFoundryDeployMetadata() config.StepData {
|
||||
{
|
||||
Name: "cfNativeDeployParameters",
|
||||
ResourceRef: []config.ResourceReference{},
|
||||
Scope: []string{"PARAMETERS", "STAGES", "STEPS"},
|
||||
Scope: []string{"PARAMETERS", "STAGES", "STEPS", "GENERAL"},
|
||||
Type: "string",
|
||||
Mandatory: false,
|
||||
Aliases: []config.Alias{},
|
||||
@ -239,7 +240,7 @@ func cloudFoundryDeployMetadata() config.StepData {
|
||||
{
|
||||
Name: "cfPluginHome",
|
||||
ResourceRef: []config.ResourceReference{},
|
||||
Scope: []string{"PARAMETERS", "STAGES", "STEPS"},
|
||||
Scope: []string{"PARAMETERS", "STAGES", "STEPS", "GENERAL"},
|
||||
Type: "string",
|
||||
Mandatory: false,
|
||||
Aliases: []config.Alias{},
|
||||
@ -247,7 +248,7 @@ func cloudFoundryDeployMetadata() config.StepData {
|
||||
{
|
||||
Name: "deployDockerImage",
|
||||
ResourceRef: []config.ResourceReference{},
|
||||
Scope: []string{"PARAMETERS", "STAGES", "STEPS"},
|
||||
Scope: []string{"PARAMETERS", "STAGES", "STEPS", "GENERAL"},
|
||||
Type: "string",
|
||||
Mandatory: false,
|
||||
Aliases: []config.Alias{},
|
||||
@ -255,15 +256,23 @@ func cloudFoundryDeployMetadata() config.StepData {
|
||||
{
|
||||
Name: "deployTool",
|
||||
ResourceRef: []config.ResourceReference{},
|
||||
Scope: []string{"PARAMETERS", "STAGES", "STEPS"},
|
||||
Scope: []string{"PARAMETERS", "STAGES", "STEPS", "GENERAL"},
|
||||
Type: "string",
|
||||
Mandatory: true,
|
||||
Mandatory: false,
|
||||
Aliases: []config.Alias{},
|
||||
},
|
||||
{
|
||||
Name: "buildTool",
|
||||
ResourceRef: []config.ResourceReference{{Name: "commonPipelineEnvironment", Param: "buildTool"}},
|
||||
Scope: []string{"PARAMETERS", "STAGES", "STEPS", "GENERAL"},
|
||||
Type: "string",
|
||||
Mandatory: false,
|
||||
Aliases: []config.Alias{},
|
||||
},
|
||||
{
|
||||
Name: "deployType",
|
||||
ResourceRef: []config.ResourceReference{},
|
||||
Scope: []string{"PARAMETERS", "STAGES", "STEPS"},
|
||||
Scope: []string{"PARAMETERS", "STAGES", "STEPS", "GENERAL"},
|
||||
Type: "string",
|
||||
Mandatory: false,
|
||||
Aliases: []config.Alias{},
|
||||
@ -295,7 +304,7 @@ func cloudFoundryDeployMetadata() config.StepData {
|
||||
{
|
||||
Name: "loginParameters",
|
||||
ResourceRef: []config.ResourceReference{},
|
||||
Scope: []string{"PARAMETERS", "STAGES", "STEPS"},
|
||||
Scope: []string{"PARAMETERS", "STAGES", "STEPS", "GENERAL"},
|
||||
Type: "string",
|
||||
Mandatory: false,
|
||||
Aliases: []config.Alias{},
|
||||
@ -303,7 +312,7 @@ func cloudFoundryDeployMetadata() config.StepData {
|
||||
{
|
||||
Name: "manifest",
|
||||
ResourceRef: []config.ResourceReference{},
|
||||
Scope: []string{"PARAMETERS", "STAGES", "STEPS"},
|
||||
Scope: []string{"PARAMETERS", "STAGES", "STEPS", "GENERAL"},
|
||||
Type: "string",
|
||||
Mandatory: false,
|
||||
Aliases: []config.Alias{{Name: "cfManifest"}, {Name: "cloudFoundry/manifest"}},
|
||||
@ -311,7 +320,7 @@ func cloudFoundryDeployMetadata() config.StepData {
|
||||
{
|
||||
Name: "manifestVariables",
|
||||
ResourceRef: []config.ResourceReference{},
|
||||
Scope: []string{"PARAMETERS", "STAGES", "STEPS"},
|
||||
Scope: []string{"PARAMETERS", "STAGES", "STEPS", "GENERAL"},
|
||||
Type: "[]string",
|
||||
Mandatory: false,
|
||||
Aliases: []config.Alias{{Name: "cfManifestVariables"}, {Name: "cloudFoundry/manifestVariables"}},
|
||||
@ -319,7 +328,7 @@ func cloudFoundryDeployMetadata() config.StepData {
|
||||
{
|
||||
Name: "manifestVariablesFiles",
|
||||
ResourceRef: []config.ResourceReference{},
|
||||
Scope: []string{"PARAMETERS", "STAGES", "STEPS"},
|
||||
Scope: []string{"PARAMETERS", "STAGES", "STEPS", "GENERAL"},
|
||||
Type: "[]string",
|
||||
Mandatory: false,
|
||||
Aliases: []config.Alias{{Name: "cfManifestVariablesFiles"}, {Name: "cloudFoundry/manifestVariablesFiles"}},
|
||||
@ -327,7 +336,7 @@ func cloudFoundryDeployMetadata() config.StepData {
|
||||
{
|
||||
Name: "mtaDeployParameters",
|
||||
ResourceRef: []config.ResourceReference{},
|
||||
Scope: []string{"PARAMETERS", "STAGES", "STEPS"},
|
||||
Scope: []string{"PARAMETERS", "STAGES", "STEPS", "GENERAL"},
|
||||
Type: "string",
|
||||
Mandatory: false,
|
||||
Aliases: []config.Alias{},
|
||||
@ -335,7 +344,7 @@ func cloudFoundryDeployMetadata() config.StepData {
|
||||
{
|
||||
Name: "mtaExtensionDescriptor",
|
||||
ResourceRef: []config.ResourceReference{},
|
||||
Scope: []string{"PARAMETERS", "STAGES", "STEPS"},
|
||||
Scope: []string{"PARAMETERS", "STAGES", "STEPS", "GENERAL"},
|
||||
Type: "string",
|
||||
Mandatory: false,
|
||||
Aliases: []config.Alias{{Name: "cloudFoundry/mtaExtensionDescriptor"}},
|
||||
@ -343,7 +352,7 @@ func cloudFoundryDeployMetadata() config.StepData {
|
||||
{
|
||||
Name: "mtaPath",
|
||||
ResourceRef: []config.ResourceReference{{Name: "commonPipelineEnvironment", Param: "mtarFilePath"}},
|
||||
Scope: []string{"PARAMETERS", "STAGES", "STEPS"},
|
||||
Scope: []string{"PARAMETERS", "STAGES", "STEPS", "GENERAL"},
|
||||
Type: "string",
|
||||
Mandatory: false,
|
||||
Aliases: []config.Alias{},
|
||||
@ -351,7 +360,7 @@ func cloudFoundryDeployMetadata() config.StepData {
|
||||
{
|
||||
Name: "org",
|
||||
ResourceRef: []config.ResourceReference{},
|
||||
Scope: []string{"PARAMETERS", "STAGES", "STEPS"},
|
||||
Scope: []string{"PARAMETERS", "STAGES", "STEPS", "GENERAL"},
|
||||
Type: "string",
|
||||
Mandatory: true,
|
||||
Aliases: []config.Alias{{Name: "cfOrg"}, {Name: "cloudFoundry/org"}},
|
||||
@ -367,7 +376,7 @@ func cloudFoundryDeployMetadata() config.StepData {
|
||||
{
|
||||
Name: "smokeTestScript",
|
||||
ResourceRef: []config.ResourceReference{},
|
||||
Scope: []string{"PARAMETERS", "STAGES", "STEPS"},
|
||||
Scope: []string{"PARAMETERS", "STAGES", "STEPS", "GENERAL"},
|
||||
Type: "string",
|
||||
Mandatory: false,
|
||||
Aliases: []config.Alias{},
|
||||
@ -375,7 +384,7 @@ func cloudFoundryDeployMetadata() config.StepData {
|
||||
{
|
||||
Name: "smokeTestStatusCode",
|
||||
ResourceRef: []config.ResourceReference{},
|
||||
Scope: []string{"PARAMETERS", "STAGES", "STEPS"},
|
||||
Scope: []string{"PARAMETERS", "STAGES", "STEPS", "GENERAL"},
|
||||
Type: "int",
|
||||
Mandatory: false,
|
||||
Aliases: []config.Alias{},
|
||||
@ -383,7 +392,7 @@ func cloudFoundryDeployMetadata() config.StepData {
|
||||
{
|
||||
Name: "space",
|
||||
ResourceRef: []config.ResourceReference{},
|
||||
Scope: []string{"PARAMETERS", "STAGES", "STEPS"},
|
||||
Scope: []string{"PARAMETERS", "STAGES", "STEPS", "GENERAL"},
|
||||
Type: "string",
|
||||
Mandatory: true,
|
||||
Aliases: []config.Alias{{Name: "cfSpace"}, {Name: "cloudFoundry/space"}},
|
||||
|
@ -985,6 +985,32 @@ func TestCfDeployment(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestValidateDeployTool(t *testing.T) {
|
||||
testCases := []struct {
|
||||
runName string
|
||||
deployToolGiven string
|
||||
buildTool string
|
||||
deployToolExpected string
|
||||
}{
|
||||
{"no params", "", "", ""},
|
||||
{"build tool MTA", "", "mta", "mtaDeployPlugin"},
|
||||
{"build tool other", "", "other", "cf_native"},
|
||||
{"deploy and build tool given", "given", "unknown", "given"},
|
||||
{"only deploy tool given", "given", "", "given"},
|
||||
}
|
||||
|
||||
t.Parallel()
|
||||
|
||||
for _, test := range testCases {
|
||||
t.Run(test.runName, func(t *testing.T) {
|
||||
config := cloudFoundryDeployOptions{BuildTool: test.buildTool, DeployTool: test.deployToolGiven}
|
||||
validateDeployTool(&config)
|
||||
assert.Equal(t, test.deployToolExpected, config.DeployTool,
|
||||
"expected different deployTool result")
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestManifestVariableFiles(t *testing.T) {
|
||||
|
||||
defer func() {
|
||||
|
@ -1,18 +1,28 @@
|
||||
metadata:
|
||||
name: cloudFoundryDeploy
|
||||
description: Deploys an application to cloud foundry
|
||||
description: "Deploys an application to Cloud Foundry"
|
||||
longDescription: |
|
||||
Deploys an application to a test or production space within Cloud Foundry.
|
||||
spec:
|
||||
inputs:
|
||||
secrets:
|
||||
- name: cfCredentialsId
|
||||
description: "Jenkins credentials ID containing user and password to authenticate to the Cloud Foundry API"
|
||||
type: jenkins
|
||||
aliases:
|
||||
- name: cloudFoundry/credentialsId
|
||||
- name: dockerCredentialsId
|
||||
description: "Jenkins credentials ID containing user and password to authenticate to the Docker registry"
|
||||
type: jenkins
|
||||
params:
|
||||
- name: apiEndpoint
|
||||
type: string
|
||||
description: "Cloud Foundry API endpoint"
|
||||
scope:
|
||||
- PARAMETERS
|
||||
- STAGES
|
||||
- STEPS
|
||||
- PARAMETERS
|
||||
- STAGES
|
||||
- STEPS
|
||||
- GENERAL
|
||||
mandatory: true
|
||||
default: "https://api.cf.eu10.hana.ondemand.com"
|
||||
aliases:
|
||||
@ -22,9 +32,10 @@ spec:
|
||||
type: string
|
||||
description: "Defines the name of the application to be deployed to the Cloud Foundry space"
|
||||
scope:
|
||||
- PARAMETERS
|
||||
- STAGES
|
||||
- STEPS
|
||||
- PARAMETERS
|
||||
- STAGES
|
||||
- STEPS
|
||||
- GENERAL
|
||||
mandatory: false
|
||||
aliases:
|
||||
- name: cfAppName
|
||||
@ -33,9 +44,10 @@ spec:
|
||||
type: string
|
||||
description: "The artifact version, used for influx reporting"
|
||||
scope:
|
||||
- PARAMETERS
|
||||
- STAGES
|
||||
- STEPS
|
||||
- PARAMETERS
|
||||
- STAGES
|
||||
- STEPS
|
||||
- GENERAL
|
||||
mandatory: false
|
||||
resourceRef:
|
||||
- name: commonPipelineEnvironment
|
||||
@ -44,113 +56,167 @@ spec:
|
||||
type: string
|
||||
description: "The cf home folder used by the cf cli. If not provided the default assumed by the cf cli is used."
|
||||
scope:
|
||||
- PARAMETERS
|
||||
- STAGES
|
||||
- STEPS
|
||||
- PARAMETERS
|
||||
- STAGES
|
||||
- STEPS
|
||||
- GENERAL
|
||||
mandatory: false
|
||||
- name: cfNativeDeployParameters
|
||||
type: string
|
||||
description: "Additional parameters passed to cf native deployment command"
|
||||
scope:
|
||||
- PARAMETERS
|
||||
- STAGES
|
||||
- STEPS
|
||||
- PARAMETERS
|
||||
- STAGES
|
||||
- STEPS
|
||||
- GENERAL
|
||||
mandatory: false
|
||||
- name: cfPluginHome
|
||||
type: string
|
||||
description: "The cf plugin home folder used by the cf cli. If not provided the default assumed by the cf cli is used."
|
||||
description: "The cf plugin home folder used by the cf cli.
|
||||
If not provided the default assumed by the cf cli is used."
|
||||
scope:
|
||||
- PARAMETERS
|
||||
- STAGES
|
||||
- STEPS
|
||||
- PARAMETERS
|
||||
- STAGES
|
||||
- STEPS
|
||||
- GENERAL
|
||||
mandatory: false
|
||||
- name: deployDockerImage
|
||||
type: string
|
||||
description: "Docker image deployments are supported (via manifest file in general)[https://docs.cloudfoundry.org/devguide/deploy-apps/manifest-attributes.html#docker]. If no manifest is used, this parameter defines the image to be deployed. The specified name of the image is passed to the `--docker-image` parameter of the cf CLI and must adhere it's naming pattern (e.g. REPO/IMAGE:TAG). See (cf CLI documentation)[https://docs.cloudfoundry.org/devguide/deploy-apps/push-docker.html] for details. Note: The used Docker registry must be visible for the targeted Cloud Foundry instance."
|
||||
description: "Docker image deployments are supported
|
||||
(via manifest file in general)[https://docs.cloudfoundry.org/devguide/deploy-apps/manifest-attributes.html#docker].
|
||||
If no manifest is used, this parameter defines the image to be deployed.
|
||||
The specified name of the image is passed to the `--docker-image` parameter of the cf CLI and must
|
||||
adhere it's naming pattern (e.g. REPO/IMAGE:TAG).
|
||||
See (cf CLI documentation)[https://docs.cloudfoundry.org/devguide/deploy-apps/push-docker.html]
|
||||
for details.
|
||||
Note: The used Docker registry must be visible for the targeted Cloud Foundry instance."
|
||||
scope:
|
||||
- PARAMETERS
|
||||
- STAGES
|
||||
- STEPS
|
||||
- PARAMETERS
|
||||
- STAGES
|
||||
- STEPS
|
||||
- GENERAL
|
||||
mandatory: false
|
||||
- name: deployTool
|
||||
type: string
|
||||
description: "Defines the tool which should be used for deployment."
|
||||
scope:
|
||||
- PARAMETERS
|
||||
- STAGES
|
||||
- STEPS
|
||||
mandatory: true
|
||||
- PARAMETERS
|
||||
- STAGES
|
||||
- STEPS
|
||||
- GENERAL
|
||||
- name: buildTool
|
||||
type: string
|
||||
description: "Defines the tool which is used for building the artifact.
|
||||
If provided, `deployTool` is automatically derived from it.
|
||||
For MTA projects, `deployTool` defaults to `mtaDeployPlugin`.
|
||||
For other projects `cf_native` will be used."
|
||||
scope:
|
||||
- PARAMETERS
|
||||
- STAGES
|
||||
- STEPS
|
||||
- GENERAL
|
||||
resourceRef:
|
||||
- name: commonPipelineEnvironment
|
||||
param: buildTool
|
||||
- name: deployType
|
||||
type: string
|
||||
description: "Defines the type of deployment, either `standard` deployment which results in a system downtime or a zero-downtime `blue-green` deployment.If 'cf_native' as deployType and 'blue-green' as deployTool is used in combination, your manifest.yaml may only contain one application. If this application has the option 'no-route' active the deployType will be changed to 'standard'."
|
||||
description: "Defines the type of deployment, either `standard` deployment which results in a system
|
||||
downtime or a zero-downtime `blue-green` deployment.If 'cf_native' as deployType and 'blue-green'
|
||||
as deployTool is used in combination, your manifest.yaml may only contain one application.
|
||||
If this application has the option 'no-route' active the deployType will be changed to 'standard'."
|
||||
scope:
|
||||
- PARAMETERS
|
||||
- STAGES
|
||||
- STEPS
|
||||
- PARAMETERS
|
||||
- STAGES
|
||||
- STEPS
|
||||
- GENERAL
|
||||
mandatory: false
|
||||
default: "standard"
|
||||
- name: dockerPassword
|
||||
type: string
|
||||
description: "dockerPassword"
|
||||
description: "If the specified image in `deployDockerImage` is contained in a Docker registry,
|
||||
which requires authorization, this defines the password to be used."
|
||||
secret: true
|
||||
scope:
|
||||
- PARAMETERS
|
||||
- STAGES
|
||||
- STEPS
|
||||
- PARAMETERS
|
||||
- STAGES
|
||||
- STEPS
|
||||
mandatory: false
|
||||
- name: dockerUsername
|
||||
type: string
|
||||
description: "dockerUserName"
|
||||
description: "If the specified image in `deployDockerImage` is contained in a Docker registry,
|
||||
which requires authorization, this defines the username to be used."
|
||||
scope:
|
||||
- PARAMETERS
|
||||
- STAGES
|
||||
- STEPS
|
||||
- PARAMETERS
|
||||
- STAGES
|
||||
- STEPS
|
||||
mandatory: false
|
||||
- name: keepOldInstance
|
||||
type: bool
|
||||
description: "In case of a `blue-green` deployment the old instance will be deleted by default. If this option is set to true the old instance will remain stopped in the Cloud Foundry space."
|
||||
description: "In case of a `blue-green` deployment the old instance will be deleted by default.
|
||||
If this option is set to true the old instance will remain stopped in the Cloud Foundry space."
|
||||
scope:
|
||||
- PARAMETERS
|
||||
- STAGES
|
||||
- STEPS
|
||||
- PARAMETERS
|
||||
- STAGES
|
||||
- STEPS
|
||||
mandatory: false
|
||||
- name: loginParameters
|
||||
type: string
|
||||
description: "Addition command line options for cf login command. No escaping/quoting is performed. Not recommanded for productive environments."
|
||||
description: "Addition command line options for cf login command. No escaping/quoting is performed.
|
||||
Not recommended for productive environments."
|
||||
scope:
|
||||
- PARAMETERS
|
||||
- STAGES
|
||||
- STEPS
|
||||
- PARAMETERS
|
||||
- STAGES
|
||||
- STEPS
|
||||
- GENERAL
|
||||
mandatory: false
|
||||
- name: manifest
|
||||
type: string
|
||||
description: "Defines the manifest to be used for deployment to Cloud Foundry."
|
||||
scope:
|
||||
- PARAMETERS
|
||||
- STAGES
|
||||
- STEPS
|
||||
- PARAMETERS
|
||||
- STAGES
|
||||
- STEPS
|
||||
- GENERAL
|
||||
mandatory: false
|
||||
aliases:
|
||||
- name: cfManifest
|
||||
- name: cloudFoundry/manifest
|
||||
- name: manifestVariables
|
||||
type: "[]string"
|
||||
description: "Defines a list of variables as key-value Map objects used for variable substitution within the file given by manifest. Defaults to an empty list, if not specified otherwise. This can be used to set variables like it is provided by 'cf push --var key=value'. The order of the maps of variables given in the list is relevant in case there are conflicting variable names and value between maps contained within the list. In case of conflicts, the last specified map in the list will win. Though each map entry in the list can contain more than one key-value pair for variable substitution, it is recommended to stick to one entry per map, and rather declare more maps within the list. The reason is that if a map in the list contains more than one key-value entry, and the entries are conflicting, the conflict resolution behavior is undefined (since map entries have no sequence). Note: variables defined via 'manifestVariables' always win over conflicting variables defined via any file given by 'manifestVariablesFiles' - no matter what is declared before. This is the same behavior as can be observed when using 'cf push --var' in combination with 'cf push --vars-file'."
|
||||
description: "Defines a list of variables as key-value Map objects used for variable substitution
|
||||
within the file given by manifest. Defaults to an empty list, if not specified otherwise.
|
||||
This can be used to set variables like it is provided by 'cf push --var key=value'.
|
||||
The order of the maps of variables given in the list is relevant in case there are conflicting
|
||||
variable names and value between maps contained within the list. In case of conflicts, the last
|
||||
specified map in the list will win. Though each map entry in the list can contain more than one
|
||||
key-value pair for variable substitution, it is recommended to stick to one entry per map,
|
||||
and rather declare more maps within the list. The reason is that if a map in the list contains
|
||||
more than one key-value entry, and the entries are conflicting, the conflict resolution behavior
|
||||
is undefined (since map entries have no sequence).
|
||||
Note: variables defined via 'manifestVariables' always win over conflicting variables defined
|
||||
via any file given by 'manifestVariablesFiles' - no matter what is declared before.
|
||||
This is the same behavior as can be observed when using 'cf push --var' in combination
|
||||
with 'cf push --vars-file'."
|
||||
scope:
|
||||
- PARAMETERS
|
||||
- STAGES
|
||||
- STEPS
|
||||
- PARAMETERS
|
||||
- STAGES
|
||||
- STEPS
|
||||
- GENERAL
|
||||
mandatory: false
|
||||
aliases:
|
||||
- name: cfManifestVariables
|
||||
- name: cloudFoundry/manifestVariables
|
||||
- name: manifestVariablesFiles
|
||||
type: "[]string"
|
||||
description: "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."
|
||||
description: "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."
|
||||
scope:
|
||||
- PARAMETERS
|
||||
- STAGES
|
||||
- STEPS
|
||||
- PARAMETERS
|
||||
- STAGES
|
||||
- STEPS
|
||||
- GENERAL
|
||||
default: "manifest-variables.yml"
|
||||
mandatory: false
|
||||
aliases:
|
||||
@ -160,18 +226,20 @@ spec:
|
||||
type: string
|
||||
description: "Additional parameters passed to mta deployment command"
|
||||
scope:
|
||||
- PARAMETERS
|
||||
- STAGES
|
||||
- STEPS
|
||||
- PARAMETERS
|
||||
- STAGES
|
||||
- STEPS
|
||||
- GENERAL
|
||||
mandatory: false
|
||||
default: "-f"
|
||||
- name: mtaExtensionDescriptor
|
||||
type: string
|
||||
description: "Defines additional extension descriptor file for deployment with the mtaDeployPlugin"
|
||||
scope:
|
||||
- PARAMETERS
|
||||
- STAGES
|
||||
- STEPS
|
||||
- PARAMETERS
|
||||
- STAGES
|
||||
- STEPS
|
||||
- GENERAL
|
||||
mandatory: false
|
||||
aliases:
|
||||
- name: cloudFoundry/mtaExtensionDescriptor
|
||||
@ -179,9 +247,10 @@ spec:
|
||||
type: string
|
||||
description: "Defines the path to *.mtar for deployment with the mtaDeployPlugin"
|
||||
scope:
|
||||
- PARAMETERS
|
||||
- STAGES
|
||||
- STEPS
|
||||
- PARAMETERS
|
||||
- STAGES
|
||||
- STEPS
|
||||
- GENERAL
|
||||
mandatory: false
|
||||
resourceRef:
|
||||
- name: commonPipelineEnvironment
|
||||
@ -190,9 +259,10 @@ spec:
|
||||
type: string
|
||||
description: "Cloud Foundry target organization."
|
||||
scope:
|
||||
- PARAMETERS
|
||||
- STAGES
|
||||
- STEPS
|
||||
- PARAMETERS
|
||||
- STAGES
|
||||
- STEPS
|
||||
- GENERAL
|
||||
aliases:
|
||||
- name: cfOrg
|
||||
- name: cloudFoundry/org
|
||||
@ -202,48 +272,54 @@ spec:
|
||||
type: string
|
||||
description: "Password"
|
||||
scope:
|
||||
- PARAMETERS
|
||||
- STAGES
|
||||
- STEPS
|
||||
- PARAMETERS
|
||||
- STAGES
|
||||
- STEPS
|
||||
mandatory: true
|
||||
secret: true
|
||||
- name: smokeTestScript
|
||||
type: string
|
||||
description: "Allows to specify a script which performs a check during blue-green deployment. The script gets the FQDN as parameter and returns `exit code 0` in case check returned `smokeTestStatusCode`. More details can be found [here](https://github.com/bluemixgaragelondon/cf-blue-green-deploy#how-to-use). Currently this option is only considered for deployTool `cf_native`."
|
||||
description: "Allows to specify a script which performs a check during blue-green deployment.
|
||||
The script gets the FQDN as parameter and returns `exit code 0` in case check returned
|
||||
`smokeTestStatusCode`.
|
||||
More details can be found [here](https://github.com/bluemixgaragelondon/cf-blue-green-deploy#how-to-use).
|
||||
Currently this option is only considered for deployTool `cf_native`."
|
||||
scope:
|
||||
- PARAMETERS
|
||||
- STAGES
|
||||
- STEPS
|
||||
- PARAMETERS
|
||||
- STAGES
|
||||
- STEPS
|
||||
- GENERAL
|
||||
mandatory: false
|
||||
default: "blueGreenCheckScript.sh"
|
||||
- name: smokeTestStatusCode
|
||||
type: int
|
||||
description: "Expected status code returned by the check."
|
||||
scope:
|
||||
- PARAMETERS
|
||||
- STAGES
|
||||
- STEPS
|
||||
- PARAMETERS
|
||||
- STAGES
|
||||
- STEPS
|
||||
- GENERAL
|
||||
mandatory: false
|
||||
default: 200
|
||||
- name: space
|
||||
type: string
|
||||
description: "Cloud Foundry target space"
|
||||
scope:
|
||||
- PARAMETERS
|
||||
- STAGES
|
||||
- STEPS
|
||||
- PARAMETERS
|
||||
- STAGES
|
||||
- STEPS
|
||||
- GENERAL
|
||||
aliases:
|
||||
- name: cfSpace
|
||||
- name: cloudFoundry/space
|
||||
mandatory: true
|
||||
secret: false
|
||||
- name: username
|
||||
type: string
|
||||
description: "User"
|
||||
scope:
|
||||
- PARAMETERS
|
||||
- STAGES
|
||||
- STEPS
|
||||
- PARAMETERS
|
||||
- STAGES
|
||||
- STEPS
|
||||
mandatory: true
|
||||
secret: true
|
||||
containers:
|
||||
|
@ -1331,4 +1331,56 @@ class CloudFoundryDeployTest extends BasePiperTest {
|
||||
],
|
||||
])
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGoStepFeatureToggleOn() {
|
||||
String calledStep = ''
|
||||
String usedMetadataFile = ''
|
||||
helper.registerAllowedMethod('piperExecuteBin', [Map, String, String, List], {
|
||||
Map parameters, String stepName,
|
||||
String metadataFile, List credentialInfo ->
|
||||
calledStep = stepName
|
||||
usedMetadataFile = metadataFile
|
||||
})
|
||||
|
||||
stepRule.step.cloudFoundryDeploy([
|
||||
script: nullScript,
|
||||
juStabUtils: utils,
|
||||
jenkinsUtilsStub: new JenkinsUtilsMock(),
|
||||
useGoStep: true,
|
||||
deployTool: 'irrelevant',
|
||||
cfOrg: 'irrelevant',
|
||||
cfSpace: 'irrelevant',
|
||||
cfCredentialsId: 'irrelevant',
|
||||
])
|
||||
|
||||
assertEquals('cloudFoundryDeploy', calledStep)
|
||||
assertEquals('metadata/cloudFoundryDeploy.yaml', usedMetadataFile)
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGoStepFeatureToggleOff() {
|
||||
String calledStep = ''
|
||||
String usedMetadataFile = ''
|
||||
helper.registerAllowedMethod('piperExecuteBin', [Map, String, String, List], {
|
||||
Map parameters, String stepName,
|
||||
String metadataFile, List credentialInfo ->
|
||||
calledStep = stepName
|
||||
usedMetadataFile = metadataFile
|
||||
})
|
||||
|
||||
stepRule.step.cloudFoundryDeploy([
|
||||
script: nullScript,
|
||||
juStabUtils: utils,
|
||||
jenkinsUtilsStub: new JenkinsUtilsMock(),
|
||||
useGoStep: 'false',
|
||||
deployTool: 'irrelevant',
|
||||
cfOrg: 'irrelevant',
|
||||
cfSpace: 'irrelevant',
|
||||
cfCredentialsId: 'irrelevant',
|
||||
])
|
||||
|
||||
assertEquals('', calledStep)
|
||||
assertEquals('', usedMetadataFile)
|
||||
}
|
||||
}
|
||||
|
@ -155,6 +155,11 @@ import static com.sap.piper.Prerequisites.checkScript
|
||||
* this defines the credentials to be used.
|
||||
*/
|
||||
'dockerCredentialsId',
|
||||
/**
|
||||
* Toggle to activate the new go-implementation of the step. Off by default.
|
||||
* @possibleValues true, false
|
||||
*/
|
||||
'useGoStep',
|
||||
]
|
||||
@Field Set STEP_CONFIG_KEYS = GENERAL_CONFIG_KEYS
|
||||
@Field Set PARAMETER_KEYS = STEP_CONFIG_KEYS
|
||||
@ -222,6 +227,15 @@ void call(Map parameters = [:]) {
|
||||
.withMandatoryProperty('cloudFoundry/credentialsId')
|
||||
.use()
|
||||
|
||||
if (config.useGoStep == true) {
|
||||
List credentials = [
|
||||
[type: 'usernamePassword', id: 'cfCredentialsId', env: ['PIPER_username', 'PIPER_password']],
|
||||
[type: 'usernamePassword', id: 'dockerCredentialsId', env: ['PIPER_dockerUsername', 'PIPER_dockerPassword']]
|
||||
]
|
||||
piperExecuteBin(parameters, STEP_NAME, 'metadata/cloudFoundryDeploy.yaml', credentials)
|
||||
return
|
||||
}
|
||||
|
||||
utils.pushToSWA([
|
||||
step: STEP_NAME,
|
||||
stepParamKey1: 'deployTool',
|
||||
|
@ -180,6 +180,7 @@ class commonPipelineEnvironment implements Serializable {
|
||||
|
||||
def files = [
|
||||
[filename: '.pipeline/commonPipelineEnvironment/artifactVersion', property: 'artifactVersion'],
|
||||
[filename: '.pipeline/commonPipelineEnvironment/buildTool', property: 'buildTool'],
|
||||
[filename: '.pipeline/commonPipelineEnvironment/originalArtifactVersion', property: 'originalArtifactVersion'],
|
||||
[filename: '.pipeline/commonPipelineEnvironment/github/owner', property: 'githubOrg'],
|
||||
[filename: '.pipeline/commonPipelineEnvironment/github/repository', property: 'githubRepo'],
|
||||
|
Loading…
Reference in New Issue
Block a user