1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2025-07-13 01:30:24 +02:00

feat(golangBuild): support private modules (#3471)

* feat(golangBuild): support private module repositories
This commit is contained in:
Christian Volk
2022-01-31 10:45:40 +01:00
committed by GitHub
parent 91420e02ff
commit 880be73a4c
9 changed files with 558 additions and 6 deletions

View File

@ -32,6 +32,8 @@ type golangBuildOptions struct {
TargetArchitectures []string `json:"targetArchitectures,omitempty"`
TestOptions []string `json:"testOptions,omitempty"`
TestResultFormat string `json:"testResultFormat,omitempty" validate:"possible-values=junit standard"`
PrivateModules string `json:"privateModules,omitempty"`
PrivateModulesGitToken string `json:"privateModulesGitToken,omitempty"`
}
// GolangBuildCommand This step will execute a golang build.
@ -70,6 +72,7 @@ If the build is successful the resulting artifact can be uploaded to e.g. a bina
log.SetErrorCategory(log.ErrorConfiguration)
return err
}
log.RegisterSecret(stepConfig.PrivateModulesGitToken)
if len(GeneralConfig.HookConfig.SentryConfig.Dsn) > 0 {
sentryHook := log.NewSentryHook(GeneralConfig.HookConfig.SentryConfig.Dsn, GeneralConfig.CorrelationID)
@ -144,6 +147,8 @@ func addGolangBuildFlags(cmd *cobra.Command, stepConfig *golangBuildOptions) {
cmd.Flags().StringSliceVar(&stepConfig.TargetArchitectures, "targetArchitectures", []string{`linux,amd64`}, "Defines the target architectures for which the build should run using OS and architecture separated by a comma.")
cmd.Flags().StringSliceVar(&stepConfig.TestOptions, "testOptions", []string{}, "Options to pass to test as per `go test` documentation (comprises e.g. flags, packages).")
cmd.Flags().StringVar(&stepConfig.TestResultFormat, "testResultFormat", `junit`, "Defines the output format of the test results.")
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.MarkFlagRequired("targetArchitectures")
}
@ -158,6 +163,9 @@ func golangBuildMetadata() config.StepData {
},
Spec: config.StepSpec{
Inputs: config.StepInputs{
Secrets: []config.StepSecrets{
{Name: "golangPrivateModulesGitTokenCredentialsId", Description: "Jenkins 'Username with password' credentials ID containing username/password for http access to your git repos where your go private modules are stored.", Type: "jenkins"},
},
Parameters: []config.StepParameters{
{
Name: "buildFlags",
@ -303,6 +311,35 @@ func golangBuildMetadata() config.StepData {
Aliases: []config.Alias{},
Default: `junit`,
},
{
Name: "privateModules",
ResourceRef: []config.ResourceReference{},
Scope: []string{"STEPS", "STAGES", "PARAMETERS"},
Type: "string",
Mandatory: false,
Aliases: []config.Alias{},
Default: os.Getenv("PIPER_privateModules"),
},
{
Name: "privateModulesGitToken",
ResourceRef: []config.ResourceReference{
{
Name: "golangPrivateModulesGitTokenCredentialsId",
Type: "secret",
},
{
Name: "golangPrivateModulesGitTokenVaultSecret",
Type: "vaultSecret",
Default: "golang",
},
},
Scope: []string{"GENERAL", "PARAMETERS", "STAGES", "STEPS"},
Type: "string",
Mandatory: false,
Aliases: []config.Alias{},
Default: os.Getenv("PIPER_privateModulesGitToken"),
},
},
},
Containers: []config.Container{