Skip to content

Commit a46b57e

Browse files
Persisted pipeline environment for golang library (#1091)
* Use commonPipelineEnvironment in go binary * Update groovy part incl. tests * Rework structure and naming * Support influx resources in steps * Update tests and some cleanups * Add correct defer handling * Address PR feedback * Fix test * Update resources.go Co-authored-by: Sven Merk <[email protected]>
1 parent e5db600 commit a46b57e

28 files changed

+1369
-468
lines changed

DEVELOPMENT.md

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
1. [Getting started](#getting-started)
66
1. [Build the project](#build-the-project_)
7+
1. [Generating step framework](#generating-step-framework)
78
1. [Logging](#logging)
89
1. [Error handling](#error-handling)
910

cmd/detectExecuteScan_generated.go

+51-41
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55

66
"github.com/SAP/jenkins-library/pkg/config"
77
"github.com/SAP/jenkins-library/pkg/log"
8+
89
"github.com/spf13/cobra"
910
)
1011

@@ -20,11 +21,11 @@ type detectExecuteScanOptions struct {
2021
}
2122

2223
var myDetectExecuteScanOptions detectExecuteScanOptions
23-
var detectExecuteScanStepConfigJSON string
2424

2525
// DetectExecuteScanCommand Executes Synopsis Detect scan
2626
func DetectExecuteScanCommand() *cobra.Command {
2727
metadata := detectExecuteScanMetadata()
28+
2829
var createDetectExecuteScanCmd = &cobra.Command{
2930
Use: "detectExecuteScan",
3031
Short: "Executes Synopsis Detect scan",
@@ -35,6 +36,7 @@ func DetectExecuteScanCommand() *cobra.Command {
3536
return PrepareConfig(cmd, &metadata, "detectExecuteScan", &myDetectExecuteScanOptions, config.OpenPiperFile)
3637
},
3738
RunE: func(cmd *cobra.Command, args []string) error {
39+
3840
return detectExecuteScan(myDetectExecuteScanOptions)
3941
},
4042
}
@@ -65,60 +67,68 @@ func detectExecuteScanMetadata() config.StepData {
6567
Inputs: config.StepInputs{
6668
Parameters: []config.StepParameters{
6769
{
68-
Name: "apiToken",
69-
Scope: []string{"PARAMETERS", "STAGES", "STEPS"},
70-
Type: "string",
71-
Mandatory: true,
72-
Aliases: []config.Alias{{Name: "detect/apiToken"}},
70+
Name: "apiToken",
71+
ResourceRef: []config.ResourceReference{},
72+
Scope: []string{"PARAMETERS", "STAGES", "STEPS"},
73+
Type: "string",
74+
Mandatory: true,
75+
Aliases: []config.Alias{{Name: "detect/apiToken"}},
7376
},
7477
{
75-
Name: "codeLocation",
76-
Scope: []string{"PARAMETERS", "STAGES", "STEPS"},
77-
Type: "string",
78-
Mandatory: false,
79-
Aliases: []config.Alias{},
78+
Name: "codeLocation",
79+
ResourceRef: []config.ResourceReference{},
80+
Scope: []string{"PARAMETERS", "STAGES", "STEPS"},
81+
Type: "string",
82+
Mandatory: false,
83+
Aliases: []config.Alias{},
8084
},
8185
{
82-
Name: "projectName",
83-
Scope: []string{"PARAMETERS", "STAGES", "STEPS"},
84-
Type: "string",
85-
Mandatory: true,
86-
Aliases: []config.Alias{{Name: "detect/projectName"}},
86+
Name: "projectName",
87+
ResourceRef: []config.ResourceReference{},
88+
Scope: []string{"PARAMETERS", "STAGES", "STEPS"},
89+
Type: "string",
90+
Mandatory: true,
91+
Aliases: []config.Alias{{Name: "detect/projectName"}},
8792
},
8893
{
89-
Name: "projectVersion",
90-
Scope: []string{"PARAMETERS", "STAGES", "STEPS"},
91-
Type: "string",
92-
Mandatory: true,
93-
Aliases: []config.Alias{{Name: "detect/projectVersion"}},
94+
Name: "projectVersion",
95+
ResourceRef: []config.ResourceReference{},
96+
Scope: []string{"PARAMETERS", "STAGES", "STEPS"},
97+
Type: "string",
98+
Mandatory: true,
99+
Aliases: []config.Alias{{Name: "detect/projectVersion"}},
94100
},
95101
{
96-
Name: "scanners",
97-
Scope: []string{"PARAMETERS", "STAGES", "STEPS"},
98-
Type: "[]string",
99-
Mandatory: false,
100-
Aliases: []config.Alias{{Name: "detect/scanners"}},
102+
Name: "scanners",
103+
ResourceRef: []config.ResourceReference{},
104+
Scope: []string{"PARAMETERS", "STAGES", "STEPS"},
105+
Type: "[]string",
106+
Mandatory: false,
107+
Aliases: []config.Alias{{Name: "detect/scanners"}},
101108
},
102109
{
103-
Name: "scanPaths",
104-
Scope: []string{"PARAMETERS", "STAGES", "STEPS"},
105-
Type: "[]string",
106-
Mandatory: false,
107-
Aliases: []config.Alias{{Name: "detect/scanPaths"}},
110+
Name: "scanPaths",
111+
ResourceRef: []config.ResourceReference{},
112+
Scope: []string{"PARAMETERS", "STAGES", "STEPS"},
113+
Type: "[]string",
114+
Mandatory: false,
115+
Aliases: []config.Alias{{Name: "detect/scanPaths"}},
108116
},
109117
{
110-
Name: "scanProperties",
111-
Scope: []string{"PARAMETERS", "STAGES", "STEPS"},
112-
Type: "[]string",
113-
Mandatory: false,
114-
Aliases: []config.Alias{{Name: "detect/scanProperties"}},
118+
Name: "scanProperties",
119+
ResourceRef: []config.ResourceReference{},
120+
Scope: []string{"PARAMETERS", "STAGES", "STEPS"},
121+
Type: "[]string",
122+
Mandatory: false,
123+
Aliases: []config.Alias{{Name: "detect/scanProperties"}},
115124
},
116125
{
117-
Name: "serverUrl",
118-
Scope: []string{"PARAMETERS", "STAGES", "STEPS"},
119-
Type: "string",
120-
Mandatory: false,
121-
Aliases: []config.Alias{{Name: "detect/serverUrl"}},
126+
Name: "serverUrl",
127+
ResourceRef: []config.ResourceReference{},
128+
Scope: []string{"PARAMETERS", "STAGES", "STEPS"},
129+
Type: "string",
130+
Mandatory: false,
131+
Aliases: []config.Alias{{Name: "detect/serverUrl"}},
122132
},
123133
},
124134
},

cmd/getConfig.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ func generateConfig() error {
5454
return errors.Wrap(err, "metadata: read failed")
5555
}
5656

57+
resourceParams := metadata.GetResourceParameters(GeneralConfig.EnvRootPath, "commonPipelineEnvironment")
58+
5759
var customConfig io.ReadCloser
5860
{
5961
exists, e := piperutils.FileExists(GeneralConfig.CustomConfig)
@@ -91,7 +93,7 @@ func generateConfig() error {
9193
params = metadata.Spec.Inputs.Parameters
9294
}
9395

94-
stepConfig, err = myConfig.GetStepConfig(flags, GeneralConfig.ParametersJSON, customConfig, defaultConfig, paramFilter, params, GeneralConfig.StageName, metadata.Metadata.Name)
96+
stepConfig, err = myConfig.GetStepConfig(flags, GeneralConfig.ParametersJSON, customConfig, defaultConfig, paramFilter, params, resourceParams, GeneralConfig.StageName, metadata.Metadata.Name)
9597
if err != nil {
9698
return errors.Wrap(err, "getting step config failed")
9799
}

cmd/githubCreatePullRequest_generated.go

+69-56
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55

66
"github.com/SAP/jenkins-library/pkg/config"
77
"github.com/SAP/jenkins-library/pkg/log"
8+
89
"github.com/spf13/cobra"
910
)
1011

@@ -23,11 +24,11 @@ type githubCreatePullRequestOptions struct {
2324
}
2425

2526
var myGithubCreatePullRequestOptions githubCreatePullRequestOptions
26-
var githubCreatePullRequestStepConfigJSON string
2727

2828
// GithubCreatePullRequestCommand Create a pull request on GitHub
2929
func GithubCreatePullRequestCommand() *cobra.Command {
3030
metadata := githubCreatePullRequestMetadata()
31+
3132
var createGithubCreatePullRequestCmd = &cobra.Command{
3233
Use: "githubCreatePullRequest",
3334
Short: "Create a pull request on GitHub",
@@ -40,6 +41,7 @@ It can for example be used for GitOps scenarios or for scenarios where you want
4041
return PrepareConfig(cmd, &metadata, "githubCreatePullRequest", &myGithubCreatePullRequestOptions, config.OpenPiperFile)
4142
},
4243
RunE: func(cmd *cobra.Command, args []string) error {
44+
4345
return githubCreatePullRequest(myGithubCreatePullRequestOptions)
4446
},
4547
}
@@ -79,81 +81,92 @@ func githubCreatePullRequestMetadata() config.StepData {
7981
Inputs: config.StepInputs{
8082
Parameters: []config.StepParameters{
8183
{
82-
Name: "assignees",
83-
Scope: []string{"PARAMETERS", "STAGES", "STEPS"},
84-
Type: "[]string",
85-
Mandatory: false,
86-
Aliases: []config.Alias{},
84+
Name: "assignees",
85+
ResourceRef: []config.ResourceReference{},
86+
Scope: []string{"PARAMETERS", "STAGES", "STEPS"},
87+
Type: "[]string",
88+
Mandatory: false,
89+
Aliases: []config.Alias{},
8790
},
8891
{
89-
Name: "base",
90-
Scope: []string{"PARAMETERS", "STAGES", "STEPS"},
91-
Type: "string",
92-
Mandatory: true,
93-
Aliases: []config.Alias{},
92+
Name: "base",
93+
ResourceRef: []config.ResourceReference{},
94+
Scope: []string{"PARAMETERS", "STAGES", "STEPS"},
95+
Type: "string",
96+
Mandatory: true,
97+
Aliases: []config.Alias{},
9498
},
9599
{
96-
Name: "body",
97-
Scope: []string{"PARAMETERS", "STAGES", "STEPS"},
98-
Type: "string",
99-
Mandatory: true,
100-
Aliases: []config.Alias{},
100+
Name: "body",
101+
ResourceRef: []config.ResourceReference{},
102+
Scope: []string{"PARAMETERS", "STAGES", "STEPS"},
103+
Type: "string",
104+
Mandatory: true,
105+
Aliases: []config.Alias{},
101106
},
102107
{
103-
Name: "apiUrl",
104-
Scope: []string{"GENERAL", "PARAMETERS", "STAGES", "STEPS"},
105-
Type: "string",
106-
Mandatory: true,
107-
Aliases: []config.Alias{{Name: "githubApiUrl"}},
108+
Name: "apiUrl",
109+
ResourceRef: []config.ResourceReference{},
110+
Scope: []string{"GENERAL", "PARAMETERS", "STAGES", "STEPS"},
111+
Type: "string",
112+
Mandatory: true,
113+
Aliases: []config.Alias{{Name: "githubApiUrl"}},
108114
},
109115
{
110-
Name: "head",
111-
Scope: []string{"PARAMETERS", "STAGES", "STEPS"},
112-
Type: "string",
113-
Mandatory: true,
114-
Aliases: []config.Alias{},
116+
Name: "head",
117+
ResourceRef: []config.ResourceReference{},
118+
Scope: []string{"PARAMETERS", "STAGES", "STEPS"},
119+
Type: "string",
120+
Mandatory: true,
121+
Aliases: []config.Alias{},
115122
},
116123
{
117-
Name: "owner",
118-
Scope: []string{"PARAMETERS", "STAGES", "STEPS"},
119-
Type: "string",
120-
Mandatory: true,
121-
Aliases: []config.Alias{{Name: "githubOrg"}},
124+
Name: "owner",
125+
ResourceRef: []config.ResourceReference{},
126+
Scope: []string{"PARAMETERS", "STAGES", "STEPS"},
127+
Type: "string",
128+
Mandatory: true,
129+
Aliases: []config.Alias{{Name: "githubOrg"}},
122130
},
123131
{
124-
Name: "repository",
125-
Scope: []string{"PARAMETERS", "STAGES", "STEPS"},
126-
Type: "string",
127-
Mandatory: true,
128-
Aliases: []config.Alias{{Name: "githubRepo"}},
132+
Name: "repository",
133+
ResourceRef: []config.ResourceReference{},
134+
Scope: []string{"PARAMETERS", "STAGES", "STEPS"},
135+
Type: "string",
136+
Mandatory: true,
137+
Aliases: []config.Alias{{Name: "githubRepo"}},
129138
},
130139
{
131-
Name: "serverUrl",
132-
Scope: []string{"GENERAL", "PARAMETERS", "STAGES", "STEPS"},
133-
Type: "string",
134-
Mandatory: true,
135-
Aliases: []config.Alias{{Name: "githubServerUrl"}},
140+
Name: "serverUrl",
141+
ResourceRef: []config.ResourceReference{},
142+
Scope: []string{"GENERAL", "PARAMETERS", "STAGES", "STEPS"},
143+
Type: "string",
144+
Mandatory: true,
145+
Aliases: []config.Alias{{Name: "githubServerUrl"}},
136146
},
137147
{
138-
Name: "title",
139-
Scope: []string{"PARAMETERS", "STAGES", "STEPS"},
140-
Type: "string",
141-
Mandatory: true,
142-
Aliases: []config.Alias{},
148+
Name: "title",
149+
ResourceRef: []config.ResourceReference{},
150+
Scope: []string{"PARAMETERS", "STAGES", "STEPS"},
151+
Type: "string",
152+
Mandatory: true,
153+
Aliases: []config.Alias{},
143154
},
144155
{
145-
Name: "token",
146-
Scope: []string{"GENERAL", "PARAMETERS", "STAGES", "STEPS"},
147-
Type: "string",
148-
Mandatory: true,
149-
Aliases: []config.Alias{{Name: "githubToken"}},
156+
Name: "token",
157+
ResourceRef: []config.ResourceReference{},
158+
Scope: []string{"GENERAL", "PARAMETERS", "STAGES", "STEPS"},
159+
Type: "string",
160+
Mandatory: true,
161+
Aliases: []config.Alias{{Name: "githubToken"}},
150162
},
151163
{
152-
Name: "labels",
153-
Scope: []string{"PARAMETERS", "STAGES", "STEPS"},
154-
Type: "[]string",
155-
Mandatory: false,
156-
Aliases: []config.Alias{},
164+
Name: "labels",
165+
ResourceRef: []config.ResourceReference{},
166+
Scope: []string{"PARAMETERS", "STAGES", "STEPS"},
167+
Type: "[]string",
168+
Mandatory: false,
169+
Aliases: []config.Alias{},
157170
},
158171
},
159172
},

0 commit comments

Comments
 (0)