mirror of
https://github.com/SAP/jenkins-library.git
synced 2025-01-18 05:18:24 +02:00
Add entryPointPath option
This commit is contained in:
parent
cd2ae89229
commit
b541e64a4f
@ -450,6 +450,9 @@ func runGolangBuildPerArchitecture(config *golangBuildOptions, utils golangBuild
|
||||
if len(ldflags) > 0 {
|
||||
buildOptions = append(buildOptions, "-ldflags", ldflags)
|
||||
}
|
||||
if config.EntryPointPath != "" {
|
||||
buildOptions = append(buildOptions, config.EntryPointPath)
|
||||
}
|
||||
|
||||
if err := utils.RunExecutable("go", buildOptions...); err != nil {
|
||||
log.Entry().Debugf("buildOptions: %v", buildOptions)
|
||||
|
@ -45,6 +45,7 @@ type golangBuildOptions struct {
|
||||
PrivateModules string `json:"privateModules,omitempty"`
|
||||
PrivateModulesGitToken string `json:"privateModulesGitToken,omitempty"`
|
||||
ArtifactVersion string `json:"artifactVersion,omitempty"`
|
||||
EntryPointPath string `json:"entryPointPath,omitempty"`
|
||||
}
|
||||
|
||||
type golangBuildCommonPipelineEnvironment struct {
|
||||
@ -236,6 +237,7 @@ func addGolangBuildFlags(cmd *cobra.Command, stepConfig *golangBuildOptions) {
|
||||
cmd.Flags().StringVar(&stepConfig.PrivateModules, "privateModules", os.Getenv("PIPER_privateModules"), "Tells go which modules shall be considered to be private (by setting [GOPRIVATE](https://pkg.go.dev/cmd/go#hdr-Configuration_for_downloading_non_public_code)).")
|
||||
cmd.Flags().StringVar(&stepConfig.PrivateModulesGitToken, "privateModulesGitToken", os.Getenv("PIPER_privateModulesGitToken"), "GitHub personal access token as per https://help.github.com/en/github/authenticating-to-github/creating-a-personal-access-token-for-the-command-line.")
|
||||
cmd.Flags().StringVar(&stepConfig.ArtifactVersion, "artifactVersion", os.Getenv("PIPER_artifactVersion"), "Version of the artifact to be built.")
|
||||
cmd.Flags().StringVar(&stepConfig.EntryPointPath, "entryPointPath", os.Getenv("PIPER_entryPointPath"), "Path to the file with main function. If empty, it is assumed that the main function is in the root of the project.")
|
||||
|
||||
cmd.MarkFlagRequired("targetArchitectures")
|
||||
}
|
||||
@ -497,6 +499,15 @@ func golangBuildMetadata() config.StepData {
|
||||
Aliases: []config.Alias{},
|
||||
Default: os.Getenv("PIPER_artifactVersion"),
|
||||
},
|
||||
{
|
||||
Name: "entryPointPath",
|
||||
ResourceRef: []config.ResourceReference{},
|
||||
Scope: []string{"PARAMETERS", "STAGES", "STEPS"},
|
||||
Type: "string",
|
||||
Mandatory: false,
|
||||
Aliases: []config.Alias{},
|
||||
Default: os.Getenv("PIPER_entryPointPath"),
|
||||
},
|
||||
},
|
||||
},
|
||||
Containers: []config.Container{
|
||||
|
@ -84,6 +84,7 @@ func TestRunGolangBuild(t *testing.T) {
|
||||
t.Run("success - no tests", func(t *testing.T) {
|
||||
config := golangBuildOptions{
|
||||
TargetArchitectures: []string{"linux,amd64"},
|
||||
EntryPointPath: "cmd/server.go",
|
||||
}
|
||||
utils := newGolangBuildTestsUtils()
|
||||
telemetryData := telemetry.CustomData{}
|
||||
@ -91,7 +92,7 @@ func TestRunGolangBuild(t *testing.T) {
|
||||
err := runGolangBuild(&config, &telemetryData, utils, &cpe)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, "go", utils.ExecMockRunner.Calls[0].Exec)
|
||||
assert.Equal(t, []string{"build", "-trimpath"}, utils.ExecMockRunner.Calls[0].Params)
|
||||
assert.Equal(t, []string{"build", "-trimpath", "cmd/server.go"}, utils.ExecMockRunner.Calls[0].Params)
|
||||
})
|
||||
|
||||
t.Run("success - tests & ldflags", func(t *testing.T) {
|
||||
|
@ -227,6 +227,13 @@ spec:
|
||||
resourceRef:
|
||||
- name: commonPipelineEnvironment
|
||||
param: artifactVersion
|
||||
- name: entryPointPath
|
||||
type: string
|
||||
description: Path to the file with main function. If empty, it is assumed that the main function is in the root of the project.
|
||||
scope:
|
||||
- PARAMETERS
|
||||
- STAGES
|
||||
- STEPS
|
||||
outputs:
|
||||
resources:
|
||||
- name: commonPipelineEnvironment
|
||||
|
Loading…
x
Reference in New Issue
Block a user