1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2024-12-12 10:55:20 +02:00

get rid of classic mta builder (#2835)

* get rid of classic mta builder

* fix yaml lint error

* adding new line in yaml

Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
This commit is contained in:
Thorsten Duda 2021-05-19 08:45:38 +02:00 committed by GitHub
parent c088e623aa
commit cdcce05145
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 21 additions and 195 deletions

View File

@ -61,7 +61,7 @@ func ValueOfBuildTarget(str string) (MTABuildTarget, error) {
case "XSA":
return XSA, nil
default:
return -1, fmt.Errorf("Unknown BuildTarget/Platform: '%s'", str)
return -1, fmt.Errorf("Unknown Platform: '%s'", str)
}
}
@ -179,44 +179,18 @@ func runMtaBuild(config mtaBuildOptions,
var call []string
switch config.MtaBuildTool {
case "classic":
mtaJar := getMarJarName(config)
buildTarget, err := ValueOfBuildTarget(config.BuildTarget)
if err != nil {
log.SetErrorCategory(log.ErrorConfiguration)
return err
}
call = append(call, "java", "-jar", mtaJar, "--mtar", mtarName, fmt.Sprintf("--build-target=%s", buildTarget), "build")
if len(config.Extensions) != 0 {
call = append(call, fmt.Sprintf("--extension=%s", config.Extensions))
}
case "cloudMbt":
platform, err := ValueOfBuildTarget(config.Platform)
if err != nil {
log.SetErrorCategory(log.ErrorConfiguration)
return err
}
call = append(call, "mbt", "build", "--mtar", mtarName, "--platform", platform.String())
if len(config.Extensions) != 0 {
call = append(call, fmt.Sprintf("--extensions=%s", config.Extensions))
}
call = append(call, "--target", "./")
default:
platform, err := ValueOfBuildTarget(config.Platform)
if err != nil {
log.SetErrorCategory(log.ErrorConfiguration)
return fmt.Errorf("Unknown mta build tool: \"%s\"", config.MtaBuildTool)
return err
}
call = append(call, "mbt", "build", "--mtar", mtarName, "--platform", platform.String())
if len(config.Extensions) != 0 {
call = append(call, fmt.Sprintf("--extensions=%s", config.Extensions))
}
call = append(call, "--target", "./")
if err = addNpmBinToPath(utils); err != nil {
return err
}
@ -267,17 +241,6 @@ func installMavenArtifacts(utils mtaBuildUtils, config mtaBuildOptions) error {
return nil
}
func getMarJarName(config mtaBuildOptions) string {
mtaJar := "mta.jar"
if len(config.MtaJarLocation) > 0 {
mtaJar = config.MtaJarLocation
}
return mtaJar
}
func addNpmBinToPath(utils mtaBuildUtils) error {
dir, _ := os.Getwd()
newPath := path.Join(dir, "node_modules", ".bin")

View File

@ -17,10 +17,7 @@ import (
)
type mtaBuildOptions struct {
BuildTarget string `json:"buildTarget,omitempty"`
MtaBuildTool string `json:"mtaBuildTool,omitempty"`
MtarName string `json:"mtarName,omitempty"`
MtaJarLocation string `json:"mtaJarLocation,omitempty"`
Extensions string `json:"extensions,omitempty"`
Platform string `json:"platform,omitempty"`
ApplicationName string `json:"applicationName,omitempty"`
@ -132,12 +129,9 @@ func MtaBuildCommand() *cobra.Command {
}
func addMtaBuildFlags(cmd *cobra.Command, stepConfig *mtaBuildOptions) {
cmd.Flags().StringVar(&stepConfig.BuildTarget, "buildTarget", `NEO`, "mtaBuildTool 'classic' only: The target platform to which the mtar can be deployed. Valid values: 'CF', 'NEO', 'XSA'.")
cmd.Flags().StringVar(&stepConfig.MtaBuildTool, "mtaBuildTool", `cloudMbt`, "Tool to use when building the MTA. Valid values: 'classic', 'cloudMbt'.")
cmd.Flags().StringVar(&stepConfig.MtarName, "mtarName", os.Getenv("PIPER_mtarName"), "The name of the generated mtar file including its extension.")
cmd.Flags().StringVar(&stepConfig.MtaJarLocation, "mtaJarLocation", `/opt/sap/mta/lib/mta.jar`, "mtaBuildTool 'classic' only: The location of the SAP Multitarget Application Archive Builder jar file, including file name and extension. If you run on Docker, this must match the location of the jar file in the container as well.")
cmd.Flags().StringVar(&stepConfig.Extensions, "extensions", os.Getenv("PIPER_extensions"), "The path to the extension descriptor file.")
cmd.Flags().StringVar(&stepConfig.Platform, "platform", `CF`, "mtaBuildTool 'cloudMbt' only: The target platform to which the mtar can be deployed.")
cmd.Flags().StringVar(&stepConfig.Platform, "platform", `CF`, "The target platform to which the mtar can be deployed.")
cmd.Flags().StringVar(&stepConfig.ApplicationName, "applicationName", os.Getenv("PIPER_applicationName"), "The name of the application which is being built. If the parameter has been provided and no `mta.yaml` exists, the `mta.yaml` will be automatically generated using this parameter and the information (`name` and `version`) from 'package.json` before the actual build starts.")
cmd.Flags().StringVar(&stepConfig.DefaultNpmRegistry, "defaultNpmRegistry", os.Getenv("PIPER_defaultNpmRegistry"), "Url to the npm registry that should be used for installing npm dependencies.")
cmd.Flags().StringVar(&stepConfig.ProjectSettingsFile, "projectSettingsFile", os.Getenv("PIPER_projectSettingsFile"), "Path or url to the mvn settings file that should be used as project settings file.")
@ -158,22 +152,6 @@ func mtaBuildMetadata() config.StepData {
Spec: config.StepSpec{
Inputs: config.StepInputs{
Parameters: []config.StepParameters{
{
Name: "buildTarget",
ResourceRef: []config.ResourceReference{},
Scope: []string{"PARAMETERS", "STAGES", "STEPS"},
Type: "string",
Mandatory: false,
Aliases: []config.Alias{},
},
{
Name: "mtaBuildTool",
ResourceRef: []config.ResourceReference{},
Scope: []string{"PARAMETERS", "STAGES", "STEPS"},
Type: "string",
Mandatory: false,
Aliases: []config.Alias{},
},
{
Name: "mtarName",
ResourceRef: []config.ResourceReference{},
@ -182,14 +160,6 @@ func mtaBuildMetadata() config.StepData {
Mandatory: false,
Aliases: []config.Alias{},
},
{
Name: "mtaJarLocation",
ResourceRef: []config.ResourceReference{},
Scope: []string{"PARAMETERS", "STAGES", "STEPS"},
Type: "string",
Mandatory: false,
Aliases: []config.Alias{},
},
{
Name: "extensions",
ResourceRef: []config.ResourceReference{},
@ -257,8 +227,7 @@ func mtaBuildMetadata() config.StepData {
},
},
Containers: []config.Container{
{Image: "devxci/mbtci:1.1.1", Conditions: []config.Condition{{ConditionRef: "strings-equal", Params: []config.Param{{Name: "mtaBuildTool", Value: "cloudMbt"}}}}},
{Image: "ppiper/mta-archive-builder:v1", Conditions: []config.Condition{{ConditionRef: "strings-equal", Params: []config.Param{{Name: "mtaBuildTool", Value: "classic"}}}}},
{Image: "devxci/mbtci:1.1.1"},
},
Outputs: config.StepOutputs{
Resources: []config.StepResources{

View File

@ -65,7 +65,7 @@ func TestMarBuild(t *testing.T) {
t.Run("Provide default npm registry", func(t *testing.T) {
utilsMock := newMtaBuildTestUtilsBundle()
options := mtaBuildOptions{ApplicationName: "myApp", MtaBuildTool: "classic", BuildTarget: "CF", DefaultNpmRegistry: "https://example.org/npm", MtarName: "myName"}
options := mtaBuildOptions{ApplicationName: "myApp", Platform: "CF", DefaultNpmRegistry: "https://example.org/npm", MtarName: "myName"}
utilsMock.AddFile("package.json", []byte("{\"name\": \"myName\", \"version\": \"1.2.3\"}"))
@ -94,7 +94,7 @@ func TestMarBuild(t *testing.T) {
utilsMock := newMtaBuildTestUtilsBundle()
options := mtaBuildOptions{ApplicationName: "myApp", MtaBuildTool: "classic", BuildTarget: "CF", MtarName: "myName"}
options := mtaBuildOptions{ApplicationName: "myApp", Platform: "CF", MtarName: "myName"}
utilsMock.AddFile("package.json", []byte("{\"name\": \"myName\", \"version\": \"1.2.3\"}"))
@ -131,7 +131,7 @@ func TestMarBuild(t *testing.T) {
utilsMock := newMtaBuildTestUtilsBundle()
options := mtaBuildOptions{ApplicationName: "myApp", MtaBuildTool: "classic", BuildTarget: "CF"}
options := mtaBuildOptions{ApplicationName: "myApp"}
utilsMock.AddFile("package.json", []byte("{\"name\": \"myName\", \"version\": \"1.2.3\"}"))
utilsMock.AddFile("mta.yaml", []byte("already there"))
@ -145,7 +145,7 @@ func TestMarBuild(t *testing.T) {
utilsMock := newMtaBuildTestUtilsBundle()
options := mtaBuildOptions{ApplicationName: "myApp", MtaBuildTool: "classic", BuildTarget: "CF"}
options := mtaBuildOptions{ApplicationName: "myApp"}
utilsMock.AddFile("package.json", []byte("{\"name\": \"myName\", \"version\": \"1.2.3\"}"))
utilsMock.AddFile("mta.yaml", []byte("already there with-${timestamp}"))
@ -155,74 +155,13 @@ func TestMarBuild(t *testing.T) {
assert.True(t, utilsMock.HasWrittenFile("mta.yaml"))
})
t.Run("Test mta build classic toolset", func(t *testing.T) {
utilsMock := newMtaBuildTestUtilsBundle()
options := mtaBuildOptions{ApplicationName: "myApp", MtaBuildTool: "classic", BuildTarget: "CF", MtarName: "myName.mtar"}
cpe.mtarFilePath = ""
utilsMock.AddFile("package.json", []byte("{\"name\": \"myName\", \"version\": \"1.2.3\"}"))
err := runMtaBuild(options, &cpe, utilsMock)
assert.Nil(t, err)
if assert.Len(t, utilsMock.Calls, 1) {
assert.Equal(t, "java", utilsMock.Calls[0].Exec)
assert.Equal(t, []string{"-jar", "mta.jar", "--mtar", "myName.mtar", "--build-target=CF", "build"}, utilsMock.Calls[0].Params)
}
assert.Equal(t, "myName.mtar", cpe.mtarFilePath)
})
t.Run("Test mta build classic toolset, mtarName from already existing mta.yaml", func(t *testing.T) {
utilsMock := newMtaBuildTestUtilsBundle()
options := mtaBuildOptions{ApplicationName: "myApp", MtaBuildTool: "classic", BuildTarget: "CF"}
cpe.mtarFilePath = ""
utilsMock.AddFile("package.json", []byte("{\"name\": \"myName\", \"version\": \"1.2.3\"}"))
utilsMock.AddFile("mta.yaml", []byte("ID: \"myNameFromMtar\""))
err := runMtaBuild(options, &cpe, utilsMock)
assert.Nil(t, err)
if assert.Len(t, utilsMock.Calls, 1) {
assert.Equal(t, "java", utilsMock.Calls[0].Exec)
assert.Equal(t, []string{"-jar", "mta.jar", "--mtar", "myNameFromMtar.mtar", "--build-target=CF", "build"}, utilsMock.Calls[0].Params)
}
})
t.Run("Test mta build classic toolset with configured mta jar", func(t *testing.T) {
utilsMock := newMtaBuildTestUtilsBundle()
options := mtaBuildOptions{ApplicationName: "myApp", MtaBuildTool: "classic", BuildTarget: "CF", MtaJarLocation: "/opt/sap/mta/lib/mta.jar", MtarName: "myName.mtar"}
utilsMock.AddFile("package.json", []byte("{\"name\": \"myName\", \"version\": \"1.2.3\"}"))
err := runMtaBuild(options, &cpe, utilsMock)
assert.Nil(t, err)
if assert.Len(t, utilsMock.Calls, 1) {
assert.Equal(t, "java", utilsMock.Calls[0].Exec)
assert.Equal(t, []string{"-jar", "/opt/sap/mta/lib/mta.jar", "--mtar", "myName.mtar", "--build-target=CF", "build"}, utilsMock.Calls[0].Params)
}
})
t.Run("Mta build mbt toolset", func(t *testing.T) {
utilsMock := newMtaBuildTestUtilsBundle()
cpe.mtarFilePath = ""
options := mtaBuildOptions{ApplicationName: "myApp", MtaBuildTool: "cloudMbt", Platform: "CF", MtarName: "myName.mtar"}
options := mtaBuildOptions{ApplicationName: "myApp", Platform: "CF", MtarName: "myName.mtar"}
utilsMock.AddFile("package.json", []byte("{\"name\": \"myName\", \"version\": \"1.2.3\"}"))
@ -244,7 +183,7 @@ func TestMarBuild(t *testing.T) {
utilsMock.CurrentDir = "root_folder/workspace"
cpe.mtarFilePath = ""
options := mtaBuildOptions{ApplicationName: "myApp", MtaBuildTool: "cloudMbt", Platform: "CF", MtarName: "myName.mtar", M2Path: ".pipeline/local_repo"}
options := mtaBuildOptions{ApplicationName: "myApp", Platform: "CF", MtarName: "myName.mtar", M2Path: ".pipeline/local_repo"}
utilsMock.AddFile("mta.yaml", []byte("ID: \"myNameFromMtar\""))
@ -262,7 +201,7 @@ func TestMarBuild(t *testing.T) {
utilsMock := newMtaBuildTestUtilsBundle()
utilsMock.AddFile("mta.yaml", []byte("ID: \"myNameFromMtar\""))
options := mtaBuildOptions{ApplicationName: "myApp", GlobalSettingsFile: "/opt/maven/settings.xml", MtaBuildTool: "cloudMbt", Platform: "CF", MtarName: "myName"}
options := mtaBuildOptions{ApplicationName: "myApp", GlobalSettingsFile: "/opt/maven/settings.xml", Platform: "CF", MtarName: "myName"}
err := runMtaBuild(options, &cpe, utilsMock)
@ -277,7 +216,7 @@ func TestMarBuild(t *testing.T) {
utilsMock := newMtaBuildTestUtilsBundle()
utilsMock.AddFile("mta.yaml", []byte("ID: \"myNameFromMtar\""))
options := mtaBuildOptions{ApplicationName: "myApp", ProjectSettingsFile: "/my/project/settings.xml", MtaBuildTool: "cloudMbt", Platform: "CF", MtarName: "myName"}
options := mtaBuildOptions{ApplicationName: "myApp", ProjectSettingsFile: "/my/project/settings.xml", Platform: "CF", MtarName: "myName"}
err := runMtaBuild(options, &cpe, utilsMock)

View File

@ -6,31 +6,6 @@ metadata:
spec:
inputs:
params:
- name: buildTarget
type: string
description: "mtaBuildTool 'classic' only: The target platform to which the mtar can be deployed. Valid values: 'CF', 'NEO', 'XSA'."
scope:
- PARAMETERS
- STAGES
- STEPS
mandatory: false
default: NEO
possibleValues:
- CF
- NEO
- XSA
- name: mtaBuildTool
type: string
description: "Tool to use when building the MTA. Valid values: 'classic', 'cloudMbt'."
scope:
- PARAMETERS
- STAGES
- STEPS
mandatory: false
default: cloudMbt
possibleValues:
- cloudMbt
- classic
- name: mtarName
type: string
description: "The name of the generated mtar file including its extension."
@ -40,15 +15,6 @@ spec:
- STEPS
mandatory: false
default:
- name: mtaJarLocation
type: string
description: "mtaBuildTool 'classic' only: The location of the SAP Multitarget Application Archive Builder jar file, including file name and extension. If you run on Docker, this must match the location of the jar file in the container as well."
scope:
- PARAMETERS
- STAGES
- STEPS
mandatory: false
default: /opt/sap/mta/lib/mta.jar
- name: extensions
type: string
description: "The path to the extension descriptor file."
@ -62,7 +28,7 @@ spec:
- name: extension
- name: platform
type: string
description: "mtaBuildTool 'cloudMbt' only: The target platform to which the mtar can be deployed."
description: "The target platform to which the mtar can be deployed."
scope:
- PARAMETERS
- STAGES
@ -143,14 +109,3 @@ spec:
- name: mtarFilePath
containers:
- image: devxci/mbtci:1.1.1
conditions:
- conditionRef: strings-equal
params:
- name: mtaBuildTool
value: cloudMbt
- image: ppiper/mta-archive-builder:v1
conditions:
- conditionRef: strings-equal
params:
- name: mtaBuildTool
value: classic