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

Golang build publish binaries and add group id (#3749)

* Add golang binaries to CPE and add groupID in coordinates

Signed-off-by: Ashly Mathew <ashly.mathew@sap.com>

* Introducing binaries as artifacts

Signed-off-by: Ashly Mathew <ashly.mathew@sap.com>
This commit is contained in:
Ashly Mathew 2022-05-05 12:39:59 +02:00 committed by GitHub
parent fe9b3a796b
commit 823ef47db6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 19 additions and 1 deletions

View File

@ -259,7 +259,9 @@ func runGolangBuild(config *golangBuildOptions, telemetryData *telemetry.CustomD
utils.SetOptions(repoClientOptions) utils.SetOptions(repoClientOptions)
var binaryArtifacts piperenv.Artifacts
for _, binary := range binaries { for _, binary := range binaries {
targetPath := fmt.Sprintf("go/%s/%s/%s", goModFile.Module.Mod.Path, config.ArtifactVersion, binary) targetPath := fmt.Sprintf("go/%s/%s/%s", goModFile.Module.Mod.Path, config.ArtifactVersion, binary)
separator := "/" separator := "/"
@ -281,7 +283,13 @@ func runGolangBuild(config *golangBuildOptions, telemetryData *telemetry.CustomD
if !(response.StatusCode == 200 || response.StatusCode == 201) { if !(response.StatusCode == 200 || response.StatusCode == 201) {
return fmt.Errorf("couldn't upload artifact, received status code %d", response.StatusCode) return fmt.Errorf("couldn't upload artifact, received status code %d", response.StatusCode)
} }
binaryArtifacts = append(binaryArtifacts, piperenv.Artifact{
Name: binary,
})
} }
commonPipelineEnvironment.artifacts = binaryArtifacts
} }
return nil return nil

View File

@ -48,7 +48,8 @@ type golangBuildOptions struct {
} }
type golangBuildCommonPipelineEnvironment struct { type golangBuildCommonPipelineEnvironment struct {
custom struct { artifacts piperenv.Artifacts
custom struct {
buildSettingsInfo string buildSettingsInfo string
} }
} }
@ -60,6 +61,7 @@ func (p *golangBuildCommonPipelineEnvironment) persist(path, resourceName string
value interface{} value interface{}
}{ }{
{category: "custom", name: "buildSettingsInfo", value: p.custom.buildSettingsInfo}, {category: "custom", name: "buildSettingsInfo", value: p.custom.buildSettingsInfo},
{category: "", name: "artifacts", value: p.artifacts},
} }
errCount := 0 errCount := 0
@ -526,6 +528,7 @@ func golangBuildMetadata() config.StepData {
Type: "piperEnvironment", Type: "piperEnvironment",
Parameters: []map[string]interface{}{ Parameters: []map[string]interface{}{
{"name": "custom/buildSettingsInfo"}, {"name": "custom/buildSettingsInfo"},
{"name": "artifacts", "type": "piperenv.Artifacts"},
}, },
}, },
{ {

View File

@ -96,6 +96,11 @@ func (m *GoMod) GetCoordinates() (Coordinates, error) {
artifactSplit := strings.Split(parsed.Module.Mod.Path, "/") artifactSplit := strings.Split(parsed.Module.Mod.Path, "/")
artifactID := artifactSplit[len(artifactSplit)-1] artifactID := artifactSplit[len(artifactSplit)-1]
result.ArtifactID = artifactID result.ArtifactID = artifactID
goModPath := parsed.Module.Mod.Path
lastIndex := strings.LastIndex(goModPath, "/")
groupID := goModPath[0:lastIndex]
result.GroupID = groupID
} }
result.Version = parsed.Module.Mod.Version result.Version = parsed.Module.Mod.Version
if result.Version == "" { if result.Version == "" {

View File

@ -240,6 +240,8 @@ spec:
type: piperEnvironment type: piperEnvironment
params: params:
- name: custom/buildSettingsInfo - name: custom/buildSettingsInfo
- name: artifacts
type: "piperenv.Artifacts"
- name: reports - name: reports
type: reports type: reports
params: params: