Skip to content

Commit

Permalink
feat(build): add buildSettingsInfo for gradleExecuteBuild (#5043)
Browse files Browse the repository at this point in the history
* creating build settings info from gradle build

* fix linting issue and typo

* fixing step description

* Apply suggestions from code review

Co-authored-by: Tilo Körner <[email protected]>

* Address code review comments

* Fix tests

* Fix tests

* Fix tests

* Fix test

---------

Co-authored-by: Christopher Fenner <[email protected]>
Co-authored-by: Tilo Körner <[email protected]>
Co-authored-by: Vyacheslav Starostin <[email protected]>
Co-authored-by: Vyacheslav Starostin <[email protected]>
  • Loading branch information
5 people authored Oct 15, 2024
1 parent af05aca commit bc8225c
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 20 deletions.
23 changes: 22 additions & 1 deletion cmd/gradleExecuteBuild.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"strings"
"text/template"

"github.com/SAP/jenkins-library/pkg/buildsettings"
"github.com/SAP/jenkins-library/pkg/command"
"github.com/SAP/jenkins-library/pkg/gradle"
"github.com/SAP/jenkins-library/pkg/log"
Expand All @@ -18,7 +19,8 @@ import (
)

const (
gradleBomFilename = "bom-gradle"
gradleBomFilename = "bom-gradle"
stepNameForBuildSettings = "gradleExecuteBuild"
)

var (
Expand Down Expand Up @@ -189,6 +191,25 @@ func runGradleExecuteBuild(config *gradleExecuteBuildOptions, telemetryData *tel
return err
}

log.Entry().Debugf("creating build settings information...")

dockerImage, err := GetDockerImageValue(stepNameForBuildSettings)
if err != nil {
return fmt.Errorf("failed to retrieve dockerImage configuration: %w", err)
}

gradleConfig := buildsettings.BuildOptions{
CreateBOM: config.CreateBOM,
Publish: config.Publish,
BuildSettingsInfo: config.BuildSettingsInfo,
DockerImage: dockerImage,
}
buildSettingsInfo, err := buildsettings.CreateBuildSettingsInfo(&gradleConfig, stepNameForBuildSettings)
if err != nil {
log.Entry().Warnf("failed to create build settings info: %v", err)
}
pipelineEnv.custom.buildSettingsInfo = buildSettingsInfo

log.Entry().Info("Publishing of artifacts to staging repository...")
if config.Publish {
if err := publishArtifacts(config, utils, pipelineEnv); err != nil {
Expand Down
21 changes: 20 additions & 1 deletion cmd/gradleExecuteBuild_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 11 additions & 11 deletions pkg/buildsettings/buildSettings.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ import (
)

type BuildSettings struct {
GolangBuild []BuildOptions `json:"golangBuild,omitempty"`
GradleBuild []BuildOptions `json:"gradleBuild,omitempty"`
HelmExecute []BuildOptions `json:"helmExecute,omitempty"`
KanikoExecute []BuildOptions `json:"kanikoExecute,omitempty"`
MavenBuild []BuildOptions `json:"mavenBuild,omitempty"`
MtaBuild []BuildOptions `json:"mtaBuild,omitempty"`
PythonBuild []BuildOptions `json:"pythonBuild,omitempty"`
NpmExecuteScripts []BuildOptions `json:"npmExecuteScripts,omitempty"`
CnbBuild []BuildOptions `json:"cnbBuild,omitempty"`
GolangBuild []BuildOptions `json:"golangBuild,omitempty"`
GradleExecuteBuild []BuildOptions `json:"gradleExecuteBuild,omitempty"`
HelmExecute []BuildOptions `json:"helmExecute,omitempty"`
KanikoExecute []BuildOptions `json:"kanikoExecute,omitempty"`
MavenBuild []BuildOptions `json:"mavenBuild,omitempty"`
MtaBuild []BuildOptions `json:"mtaBuild,omitempty"`
PythonBuild []BuildOptions `json:"pythonBuild,omitempty"`
NpmExecuteScripts []BuildOptions `json:"npmExecuteScripts,omitempty"`
CnbBuild []BuildOptions `json:"cnbBuild,omitempty"`
}

type BuildOptions struct {
Expand Down Expand Up @@ -74,9 +74,9 @@ func CreateBuildSettingsInfo(config *BuildOptions, buildTool string) (string, er
jsonResult, err = json.Marshal(BuildSettings{
GolangBuild: settings,
})
case "gradleBuild":
case "gradleExecuteBuild":
jsonResult, err = json.Marshal(BuildSettings{
GradleBuild: settings,
GradleExecuteBuild: settings,
})
case "helmExecute":
jsonResult, err = json.Marshal(BuildSettings{
Expand Down
11 changes: 4 additions & 7 deletions pkg/buildsettings/buildSettings_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
//go:build unit
// +build unit

package buildsettings

import (
Expand Down Expand Up @@ -28,9 +25,9 @@ func TestCreateBuildSettingsInfo(t *testing.T) {
expected: "{\"golangBuild\":[{\"dockerImage\":\"golang:latest\"}]}",
},
{
config: BuildOptions{CreateBOM: true},
buildTool: "gradleBuild",
expected: "{\"gradleBuild\":[{\"createBOM\":true}]}",
config: BuildOptions{CreateBOM: true, DockerImage: "gradle:latest"},
buildTool: "gradleExecuteBuild",
expected: "{\"gradleExecuteBuild\":[{\"createBOM\":true,\"dockerImage\":\"gradle:latest\"}]}",
},
{
config: BuildOptions{Publish: true},
Expand Down Expand Up @@ -77,7 +74,7 @@ func TestCreateBuildSettingsInfo(t *testing.T) {
for _, testCase := range testTableConfig {
buildSettings, err := CreateBuildSettingsInfo(&testCase.config, testCase.buildTool)
assert.Nil(t, err)
assert.Equal(t, buildSettings, testCase.expected)
assert.Equal(t, testCase.expected, buildSettings)
}
})

Expand Down
11 changes: 11 additions & 0 deletions resources/metadata/gradleExecuteBuild.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,16 @@ spec:
- PARAMETERS
- STAGES
- STEPS
- name: buildSettingsInfo
type: string
description: build settings info is typically filled by the step automatically to create information about the build settings that were used during the gradle build. This information is typically used for compliance related processes.
scope:
- STEPS
- STAGES
- PARAMETERS
resourceRef:
- name: commonPipelineEnvironment
param: custom/buildSettingsInfo
outputs:
resources:
- name: reports
Expand All @@ -169,6 +179,7 @@ spec:
params:
- name: custom/artifacts
type: "piperenv.Artifacts"
- name: custom/buildSettingsInfo
containers:
- name: gradle
image: gradle:6-jdk11-alpine

0 comments on commit bc8225c

Please sign in to comment.