diff --git a/cmd/getConfig.go b/cmd/getConfig.go index c37614b68..277daf99e 100644 --- a/cmd/getConfig.go +++ b/cmd/getConfig.go @@ -6,6 +6,7 @@ import ( "os" "github.com/SAP/jenkins-library/pkg/config" + "github.com/SAP/jenkins-library/pkg/log" "github.com/pkg/errors" "github.com/spf13/cobra" ) @@ -28,8 +29,16 @@ func ConfigCommand() *cobra.Command { var createConfigCmd = &cobra.Command{ Use: "getConfig", Short: "Loads the project 'Piper' configuration respecting defaults and parameters.", - RunE: func(cmd *cobra.Command, _ []string) error { - return generateConfig() + PreRun: func(cmd *cobra.Command, args []string) { + path, _ := os.Getwd() + fatalHook := &log.FatalHook{CorrelationID: GeneralConfig.CorrelationID, Path: path} + log.RegisterHook(fatalHook) + }, + Run: func(cmd *cobra.Command, _ []string) { + err := generateConfig() + if err != nil { + log.Entry().WithField("category", "config").WithError(err).Fatal("failed to retrieve configuration") + } }, } diff --git a/cmd/getConfig_test.go b/cmd/getConfig_test.go index 0ec319884..a97c8b905 100644 --- a/cmd/getConfig_test.go +++ b/cmd/getConfig_test.go @@ -54,8 +54,7 @@ func TestConfigCommand(t *testing.T) { t.Run("Run", func(t *testing.T) { t.Run("Success case", func(t *testing.T) { configOptions.openFile = configOpenFileMock - err := cmd.RunE(cmd, []string{}) - assert.NoError(t, err, "error occured but none expected") + cmd.Run(cmd, []string{}) }) }) } diff --git a/test/groovy/PiperExecuteBinTest.groovy b/test/groovy/PiperExecuteBinTest.groovy index 9050bb563..f43d43816 100644 --- a/test/groovy/PiperExecuteBinTest.groovy +++ b/test/groovy/PiperExecuteBinTest.groovy @@ -315,7 +315,7 @@ class PiperExecuteBinTest extends BasePiperTest { helper.registerAllowedMethod('sh', [String.class], {s -> throw new AbortException('exit code 1')}) exception.expect(AbortException) - exception.expectMessage("[noDetailsStep] Step execution failed. Error: hudson.AbortException: exit code 1") + exception.expectMessage("[noDetailsStep] Step execution failed. Error: hudson.AbortException: exit code 1, please see log file for more details.") stepRule.step.piperExecuteBin( [ diff --git a/vars/piperExecuteBin.groovy b/vars/piperExecuteBin.groovy index b4fc240a8..71c8e64c5 100644 --- a/vars/piperExecuteBin.groovy +++ b/vars/piperExecuteBin.groovy @@ -58,8 +58,11 @@ void call(Map parameters = [:], stepName, metadataFile, List credentialInfo, fai echo "PIPER_parametersJSON: ${groovy.json.JsonOutput.toJson(stepParameters)}" // get context configuration - Map config = readJSON(text: sh(returnStdout: true, script: "${piperGoPath} getConfig --contextConfig --stepMetadata '.pipeline/tmp/${metadataFile}'${defaultConfigArgs}${customConfigArg}")) - echo "Context Config: ${config}" + Map config + handleErrorDetails(stepName) { + config = readJSON(text: sh(returnStdout: true, script: "${piperGoPath} getConfig --contextConfig --stepMetadata '.pipeline/tmp/${metadataFile}'${defaultConfigArgs}${customConfigArg}")) + echo "Context Config: ${config}" + } dockerWrapper(script, config) { handleErrorDetails(stepName) { @@ -170,6 +173,6 @@ void handleErrorDetails(String stepName, Closure body) { } error "[${stepName}] Step execution failed${errorCategory}. Error: ${errorDetails.error?:errorDetails.message}" } - error "[${stepName}] Step execution failed. Error: ${ex}" + error "[${stepName}] Step execution failed. Error: ${ex}, please see log file for more details." } }