You've already forked sap-jenkins-library
mirror of
https://github.com/SAP/jenkins-library.git
synced 2025-11-06 09:09:19 +02:00
chore: update error categories (#2827)
This commit is contained in:
@@ -3,8 +3,6 @@ package cmd
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
piperhttp "github.com/SAP/jenkins-library/pkg/http"
|
||||
"github.com/SAP/jenkins-library/pkg/piperutils"
|
||||
"io"
|
||||
netHttp "net/http"
|
||||
"os"
|
||||
@@ -12,6 +10,9 @@ import (
|
||||
"text/template"
|
||||
"time"
|
||||
|
||||
piperhttp "github.com/SAP/jenkins-library/pkg/http"
|
||||
"github.com/SAP/jenkins-library/pkg/piperutils"
|
||||
|
||||
"github.com/SAP/jenkins-library/pkg/command"
|
||||
gitUtils "github.com/SAP/jenkins-library/pkg/git"
|
||||
"github.com/SAP/jenkins-library/pkg/log"
|
||||
@@ -187,6 +188,9 @@ func runArtifactPrepareVersion(config *artifactPrepareVersionOptions, telemetryD
|
||||
// commit changes and push to repository (including new version tag)
|
||||
gitCommitID, err = pushChanges(config, newVersion, repository, worktree, now)
|
||||
if err != nil {
|
||||
if strings.Contains(fmt.Sprint(err), "reference already exists") {
|
||||
log.SetErrorCategory(log.ErrorCustom)
|
||||
}
|
||||
return errors.Wrapf(err, "failed to push changes for version '%v'", newVersion)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,8 @@ package cmd
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/SAP/jenkins-library/pkg/log"
|
||||
"github.com/SAP/jenkins-library/pkg/telemetry"
|
||||
@@ -32,6 +34,9 @@ func runGithubSetCommitStatus(ctx context.Context, config *githubSetCommitStatus
|
||||
status := github.RepoStatus{Context: &config.Context, Description: &config.Description, State: &config.Status, TargetURL: &config.TargetURL}
|
||||
_, _, err := ghRepositoriesService.CreateStatus(ctx, config.Owner, config.Repository, config.CommitID, &status)
|
||||
if err != nil {
|
||||
if strings.Contains(fmt.Sprint(err), "No commit found for SHA") {
|
||||
log.SetErrorCategory(log.ErrorCustom)
|
||||
}
|
||||
return errors.Wrapf(err, "failed to set status '%v' on commitId '%v'", config.Status, config.CommitID)
|
||||
}
|
||||
return nil
|
||||
|
||||
@@ -71,6 +71,7 @@ func runKanikoExecute(config *kanikoExecuteOptions, telemetryData *telemetry.Cus
|
||||
if len(config.ContainerRegistryURL) > 0 && len(config.ContainerImageName) > 0 && len(config.ContainerImageTag) > 0 {
|
||||
containerRegistry, err := docker.ContainerRegistryFromURL(config.ContainerRegistryURL)
|
||||
if err != nil {
|
||||
log.SetErrorCategory(log.ErrorConfiguration)
|
||||
return errors.Wrapf(err, "failed to read registry url %v", config.ContainerRegistryURL)
|
||||
}
|
||||
containerImageTag := fmt.Sprintf("%v:%v", config.ContainerImageName, strings.ReplaceAll(config.ContainerImageTag, "+", "-"))
|
||||
@@ -80,6 +81,7 @@ func runKanikoExecute(config *kanikoExecuteOptions, telemetryData *telemetry.Cus
|
||||
} else if len(config.ContainerImage) > 0 {
|
||||
containerRegistry, err := docker.ContainerRegistryFromImage(config.ContainerImage)
|
||||
if err != nil {
|
||||
log.SetErrorCategory(log.ErrorConfiguration)
|
||||
return errors.Wrapf(err, "invalid registry part in image %v", config.ContainerImage)
|
||||
}
|
||||
// errors are already caught with previous call to docker.ContainerRegistryFromImage
|
||||
@@ -113,6 +115,7 @@ func runKanikoExecute(config *kanikoExecuteOptions, telemetryData *telemetry.Cus
|
||||
|
||||
err = execRunner.RunExecutable("/kaniko/executor", kanikoOpts...)
|
||||
if err != nil {
|
||||
log.SetErrorCategory(log.ErrorBuild)
|
||||
return errors.Wrap(err, "execution of '/kaniko/executor' failed")
|
||||
}
|
||||
return nil
|
||||
|
||||
@@ -26,6 +26,7 @@ func runKarma(config karmaExecuteTestsOptions, command command.ExecRunner) {
|
||||
command.SetDir(module)
|
||||
err := command.RunExecutable(installCommandTokens[0], installCommandTokens[1:]...)
|
||||
if err != nil {
|
||||
log.SetErrorCategory(log.ErrorCustom)
|
||||
log.Entry().
|
||||
WithError(err).
|
||||
WithField("command", config.InstallCommand).
|
||||
@@ -35,6 +36,7 @@ func runKarma(config karmaExecuteTestsOptions, command command.ExecRunner) {
|
||||
command.SetDir(module)
|
||||
err = command.RunExecutable(runCommandTokens[0], runCommandTokens[1:]...)
|
||||
if err != nil {
|
||||
log.SetErrorCategory(log.ErrorTest)
|
||||
log.Entry().
|
||||
WithError(err).
|
||||
WithField("command", config.RunCommand).
|
||||
|
||||
@@ -12,6 +12,7 @@ func npmExecuteScripts(config npmExecuteScriptsOptions, telemetryData *telemetry
|
||||
|
||||
err := runNpmExecuteScripts(npmExecutor, &config)
|
||||
if err != nil {
|
||||
log.SetErrorCategory(log.ErrorBuild)
|
||||
log.Entry().WithError(err).Fatal("step execution failed")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,6 +35,7 @@ func runUIVeri5(config *uiVeri5ExecuteTestsOptions, command command.ExecRunner)
|
||||
|
||||
installCommandTokens := strings.Split(config.InstallCommand, " ")
|
||||
if err := command.RunExecutable(installCommandTokens[0], installCommandTokens[1:]...); err != nil {
|
||||
log.SetErrorCategory(log.ErrorCustom)
|
||||
return errors.Wrapf(err, "failed to execute install command: %v", config.InstallCommand)
|
||||
}
|
||||
|
||||
@@ -43,6 +44,7 @@ func runUIVeri5(config *uiVeri5ExecuteTestsOptions, command command.ExecRunner)
|
||||
return errors.Errorf("parameter testOptions no longer supported, please use runOptions parameter instead.")
|
||||
}
|
||||
if err := command.RunExecutable(config.RunCommand, config.RunOptions...); err != nil {
|
||||
log.SetErrorCategory(log.ErrorTest)
|
||||
return errors.Wrapf(err, "failed to execute run command: %v %v", config.RunCommand, strings.Join(config.RunOptions, " "))
|
||||
}
|
||||
return nil
|
||||
|
||||
@@ -131,6 +131,9 @@ func runWhitesourceExecuteScan(config *ScanOptions, scan *ws.Scan, utils whiteso
|
||||
}
|
||||
|
||||
if err := resolveProjectIdentifiers(config, scan, utils, sys); err != nil {
|
||||
if strings.Contains(fmt.Sprint(err), "User is not allowed to perform this action") {
|
||||
log.SetErrorCategory(log.ErrorConfiguration)
|
||||
}
|
||||
return fmt.Errorf("failed to resolve project identifiers: %w", err)
|
||||
}
|
||||
|
||||
@@ -166,6 +169,9 @@ func runWhitesourceScan(config *ScanOptions, scan *ws.Scan, utils whitesourceUti
|
||||
dClient := &piperDocker.Client{}
|
||||
dClient.SetOptions(dClientOptions)
|
||||
if err := runContainerSaveImage(&saveImageOptions, &telemetry.CustomData{}, "./cache", "", dClient); err != nil {
|
||||
if strings.Contains(fmt.Sprint(err), "no image found") {
|
||||
log.SetErrorCategory(log.ErrorConfiguration)
|
||||
}
|
||||
return errors.Wrapf(err, "failed to dowload Docker image %v", config.ScanImage)
|
||||
}
|
||||
|
||||
@@ -573,6 +579,7 @@ func checkProjectSecurityViolations(cvssSeverityLimit float64, project ws.Projec
|
||||
}
|
||||
// https://github.com/SAP/jenkins-library/blob/master/vars/whitesourceExecuteScan.groovy#L558
|
||||
if severeVulnerabilities > 0 {
|
||||
log.SetErrorCategory(log.ErrorCompliance)
|
||||
return severeVulnerabilities, alerts, fmt.Errorf("%v Open Source Software Security vulnerabilities with CVSS score greater "+
|
||||
"or equal to %.1f detected in project %s",
|
||||
severeVulnerabilities, cvssSeverityLimit, project.Name)
|
||||
|
||||
Reference in New Issue
Block a user