SAP / jenkins-library

Jenkins shared library for Continuous Delivery pipelines.
https://www.project-piper.io
Apache License 2.0
778 stars 586 forks source link

Custom defaults are always ignored #2608

Closed jomora closed 2 years ago

jomora commented 3 years ago

I have set up a repository for custom defaults according to https://github.wdf.sap.corp/ContinuousDelivery/piper-customDefaultConfiguration

It seems that custom defaults are always ignored if they are set:

https://github.com/SAP/jenkins-library/blob/006aaab50d8328936e6a11ccbef822da5c27e0b5/vars/piperExecuteBin.groovy#L125-L128

Build output:

6:30:56  + ./piper whitesourceExecuteScan --defaultConfig .pipeline/custom-defaults.yml --ignoreCustomDefaults
16:30:57  info  whitesourceExecuteScan - Using stageName 'Code Scan' from env variable 'STAGE_NAME'
16:30:57  info  whitesourceExecuteScan - Project config: '.pipeline/config.yaml'
16:30:57  info  whitesourceExecuteScan - Project defaults: '.pipeline/custom-defaults.yml'
16:30:57  info  whitesourceExecuteScan - Ignoring custom defaults from pipeline config
16:30:57  Error: required flag(s) "buildTool" not set
16:30:57  Usage:
16:30:57    piper whitesourceExecuteScan [flags]

Expectation: If I add custom defaults I want them to be taken into account.

CCFenner commented 3 years ago
Ignoring custom defaults from pipeline config

The custom defaults are ignored if set in your config.yaml file. Files provided as described in the repo via step parameter are not affected.

@stippi2 any further comments?

stippi2 commented 3 years ago

The log output is just confusing. The problem is that the piper binary, when running in a docker image, may not have access to the custom defaults. However, the Groovy layer will already have downloaded them and persisted them in the .pipeline folder in the workspace. So the Groovy wrapper for each Go step will pass the custom defaults via --defaultConfig ${customDefaults} parameter and then tell the Go layer that it can ignore the custom defaults (because they are passed via other means). So --ignoreCustomDefaults prevents the defaults from being taken into account twice and also prevents errors when the Go step would have no access rights to the resource. We should maybe just remove the log output, but in the command line for the piper binary, it would still appear. Maybe rename the parameter... "customDefaultsAlreadyIncludedInDefaultConfigList"?

raumB commented 3 years ago

@stippi2 With the most current Piper library version my pipelines consuming custom defaults break because apparently custom default parameters are not available at the point in time when they are needed. I noticed this for the post actions when it comes down to send e-mail notifications, for example.

But I have also this issue: my custom defaults provide some configuration for some stage whereas my local pipeline configuration does not need to add or change this central configuration and therefore does not define anything for that same stage. When the pipeline runs this stage is not being executed but ignored. Only when I repeat the central configuration locally the stage is invoked.

This comment is not about to report these issues I encountered but to ask for some guidance about how I could analyze such issues best.

raumB commented 3 years ago

Duplicate: https://github.com/SAP/jenkins-library/issues/2272 ?

Maybe the Go step executed in my breaking stage just wants to download the secured custom defaults once more, despite the fact that it is not necessary anymore. My log reads this error message: https://github.com/SAP/jenkins-library/blob/master/cmd/getConfig.go#L46 .

raumB commented 3 years ago

I was now monitoring all the .yml and .yaml files in the .pipeline folder in the workspaces during pipeline execution. Well, all the different configuration sources seem to be there (custom defaults, local configuration, Piper defaults), but is there also one .yml file that would contain the merged configuration? Such a file would be extremely helpful to check if or if not a certain parameter from the different configuration sources was considered or not. But maybe such a file is not being computed nor stashed at all. How could I check during after pipeline execution which overall pipeline configuration is / was being used?

stippi2 commented 3 years ago

but is there also one .yml file that would contain the merged configuration?

No, because the "merged" configuration is step-specific and dynamic based on which stage a step runs in. The stage configuration takes precedence over step configuration.

github-actions[bot] commented 2 years ago

Thank you for your contribution! This issue is stale because it has been open 60 days with no activity. In order to keep it open, please remove stale label or add a comment within the next 10 days. If you need a Piper team member to remove the stale label make sure to add @SAP/jenkins-library-team to your comment.