mirror of
https://github.com/SAP/jenkins-library.git
synced 2025-01-30 05:59:39 +02:00
Add gcs upload to gaugeExecuteTests step (#3410)
* Add gcs upload to gaugeExecuteTests step * go generate Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
This commit is contained in:
parent
ab9848d49e
commit
c19a94032c
@ -6,14 +6,18 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/SAP/jenkins-library/pkg/config"
|
||||
"github.com/SAP/jenkins-library/pkg/gcs"
|
||||
"github.com/SAP/jenkins-library/pkg/log"
|
||||
"github.com/SAP/jenkins-library/pkg/piperenv"
|
||||
"github.com/SAP/jenkins-library/pkg/splunk"
|
||||
"github.com/SAP/jenkins-library/pkg/telemetry"
|
||||
"github.com/SAP/jenkins-library/pkg/validation"
|
||||
"github.com/bmatcuk/doublestar"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
@ -57,6 +61,43 @@ func (i *gaugeExecuteTestsInflux) persist(path, resourceName string) {
|
||||
}
|
||||
}
|
||||
|
||||
type gaugeExecuteTestsReports struct {
|
||||
}
|
||||
|
||||
func (p *gaugeExecuteTestsReports) persist(stepConfig gaugeExecuteTestsOptions, gcpJsonKeyFilePath string, gcsBucketId string, gcsFolderPath string, gcsSubFolder string) {
|
||||
if gcsBucketId == "" {
|
||||
log.Entry().Info("persisting reports to GCS is disabled, because gcsBucketId is empty")
|
||||
return
|
||||
}
|
||||
log.Entry().Info("Uploading reports to Google Cloud Storage...")
|
||||
content := []gcs.ReportOutputParam{
|
||||
{FilePattern: "**/TEST-*.xml", ParamRef: "", StepResultType: "acceptance-test"},
|
||||
{FilePattern: "**/requirement.mapping", ParamRef: "", StepResultType: "requirement-mapping"},
|
||||
{FilePattern: "**/delivery.mapping", ParamRef: "", StepResultType: "delivery-mapping"},
|
||||
}
|
||||
envVars := []gcs.EnvVar{
|
||||
{Name: "GOOGLE_APPLICATION_CREDENTIALS", Value: gcpJsonKeyFilePath, Modified: false},
|
||||
}
|
||||
gcsClient, err := gcs.NewClient(gcs.WithEnvVars(envVars))
|
||||
if err != nil {
|
||||
log.Entry().Errorf("creation of GCS client failed: %v", err)
|
||||
}
|
||||
defer gcsClient.Close()
|
||||
structVal := reflect.ValueOf(&stepConfig).Elem()
|
||||
inputParameters := map[string]string{}
|
||||
for i := 0; i < structVal.NumField(); i++ {
|
||||
field := structVal.Type().Field(i)
|
||||
if field.Type.String() == "string" {
|
||||
paramName := strings.Split(field.Tag.Get("json"), ",")
|
||||
paramValue, _ := structVal.Field(i).Interface().(string)
|
||||
inputParameters[paramName[0]] = paramValue
|
||||
}
|
||||
}
|
||||
if err := gcs.PersistReportsToGCS(gcsClient, content, inputParameters, gcsFolderPath, gcsBucketId, gcsSubFolder, doublestar.Glob, os.Stat); err != nil {
|
||||
log.Entry().Errorf("failed to persist reports: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
// GaugeExecuteTestsCommand Installs gauge and executes specified gauge tests.
|
||||
func GaugeExecuteTestsCommand() *cobra.Command {
|
||||
const STEP_NAME = "gaugeExecuteTests"
|
||||
@ -65,6 +106,7 @@ func GaugeExecuteTestsCommand() *cobra.Command {
|
||||
var stepConfig gaugeExecuteTestsOptions
|
||||
var startTime time.Time
|
||||
var influx gaugeExecuteTestsInflux
|
||||
var reports gaugeExecuteTestsReports
|
||||
var logCollector *log.CollectorHook
|
||||
var splunkClient *splunk.Splunk
|
||||
telemetryClient := &telemetry.Telemetry{}
|
||||
@ -127,6 +169,7 @@ You can use the [sample projects](https://github.com/getgauge/gauge-mvn-archetyp
|
||||
stepTelemetryData.ErrorCode = "1"
|
||||
handler := func() {
|
||||
influx.persist(GeneralConfig.EnvRootPath, "influx")
|
||||
reports.persist(stepConfig, GeneralConfig.GCPJsonKeyFilePath, GeneralConfig.GCSBucketId, GeneralConfig.GCSFolderPath, GeneralConfig.GCSSubFolder)
|
||||
config.RemoveVaultSecretFiles()
|
||||
stepTelemetryData.Duration = fmt.Sprintf("%v", time.Since(startTime).Milliseconds())
|
||||
stepTelemetryData.ErrorCategory = log.GetErrorCategory().String()
|
||||
@ -237,6 +280,15 @@ func gaugeExecuteTestsMetadata() config.StepData {
|
||||
{"name": "step_data", "fields": []map[string]string{{"name": "gauge"}}},
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "reports",
|
||||
Type: "reports",
|
||||
Parameters: []map[string]interface{}{
|
||||
{"filePattern": "**/TEST-*.xml", "type": "acceptance-test"},
|
||||
{"filePattern": "**/requirement.mapping", "type": "requirement-mapping"},
|
||||
{"filePattern": "**/delivery.mapping", "type": "delivery-mapping"},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -64,6 +64,15 @@ spec:
|
||||
fields:
|
||||
- name: gauge
|
||||
type: bool
|
||||
- name: reports
|
||||
type: reports
|
||||
params:
|
||||
- filePattern: "**/TEST-*.xml"
|
||||
type: acceptance-test
|
||||
- filePattern: "**/requirement.mapping"
|
||||
type: requirement-mapping
|
||||
- filePattern: "**/delivery.mapping"
|
||||
type: delivery-mapping
|
||||
containers:
|
||||
- name: gauge
|
||||
image: node:lts-stretch
|
||||
|
Loading…
x
Reference in New Issue
Block a user