2020-01-28 00:40:53 +02:00
|
|
|
package piperutils
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
2020-02-03 16:25:49 +02:00
|
|
|
"fmt"
|
2020-01-28 00:40:53 +02:00
|
|
|
|
|
|
|
"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"`
|
2020-02-03 16:25:49 +02:00
|
|
|
Scope string `json:"scope"`
|
2020-01-28 00:40:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// PersistReportsAndLinks stores the report paths and links in JSON format in the workspace for processing outside
|
2020-02-03 16:25:49 +02:00
|
|
|
func PersistReportsAndLinks(stepName, workspace string, reports, links []Path) {
|
2020-01-28 00:40:53 +02:00
|
|
|
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")
|
|
|
|
}
|
2020-02-03 16:25:49 +02:00
|
|
|
piperenv.SetParameter(workspace, fmt.Sprintf("%v_reports.json", stepName), string(reportList))
|
2020-01-28 00:40:53 +02:00
|
|
|
|
|
|
|
linkList, err := json.Marshal(&links)
|
|
|
|
if err != nil {
|
|
|
|
log.Entry().Errorln("Failed to marshall links.json data for archiving")
|
|
|
|
} else {
|
2020-02-03 16:25:49 +02:00
|
|
|
piperenv.SetParameter(workspace, fmt.Sprintf("%v_links.json", stepName), string(linkList))
|
2020-01-28 00:40:53 +02:00
|
|
|
}
|
|
|
|
}
|