1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2024-12-12 10:55:20 +02:00
sap-jenkins-library/pkg/piperutils/stepResults.go
Christopher Fenner 57f5e436a6
fix: improve stepResults handling (#1425)
* set read permission on created files

* handle empty report lists

* remove test output

* remove duplicate asserts

* remove unnecessary asserts
2020-04-20 16:18:49 +02:00

51 lines
1.3 KiB
Go

package piperutils
import (
"encoding/json"
"fmt"
"github.com/SAP/jenkins-library/pkg/log"
"github.com/SAP/jenkins-library/pkg/piperenv"
)
// Path - struct to serialize paths and some metadata back to the invoker
type Path struct {
Name string `json:"name"`
Target string `json:"target"`
Mandatory bool `json:"mandatory"`
Scope string `json:"scope"`
}
// PersistReportsAndLinks stores the report paths and links in JSON format in the workspace for processing outside
func PersistReportsAndLinks(stepName, workspace string, reports, links []Path) {
if reports == nil {
reports = []Path{}
}
if links == nil {
links = []Path{}
}
hasMandatoryReport := false
for _, report := range reports {
if report.Mandatory {
hasMandatoryReport = true
break
}
}
reportList, err := json.Marshal(&reports)
if err != nil {
if hasMandatoryReport {
log.Entry().Fatalln("Failed to marshall reports.json data for archiving")
}
log.Entry().Errorln("Failed to marshall reports.json data for archiving")
}
piperenv.SetParameter(workspace, fmt.Sprintf("%v_reports.json", stepName), string(reportList))
linkList, err := json.Marshal(&links)
if err != nil {
log.Entry().Errorln("Failed to marshall links.json data for archiving")
} else {
piperenv.SetParameter(workspace, fmt.Sprintf("%v_links.json", stepName), string(linkList))
}
}