1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2024-12-12 10:55:20 +02:00

Collect buildTool in cnbBuild metrics (#3530)

This commit is contained in:
Johannes Dillmann 2022-02-14 15:16:45 +01:00 committed by GitHub
parent d5a1dae660
commit 32acc9f91f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 51 additions and 26 deletions

View File

@ -53,6 +53,7 @@ type cnbBuildTelemetryData struct {
BuildEnv cnbBuildTelemetryDataBuildEnv `json:"buildEnv"`
Buildpacks cnbBuildTelemetryDataBuildpacks `json:"buildpacks"`
ProjectDescriptor cnbBuildTelemetryDataProjectDescriptor `json:"projectDescriptor"`
BuildTool string `json:"buildTool"`
}
type cnbBuildTelemetryDataBuildEnv struct {
@ -323,7 +324,7 @@ func addConfigTelemetryData(utils cnbutils.BuildUtils, data *cnbBuildTelemetryDa
data.ImageTag = config.ContainerImageTag
data.AdditionalTags = config.AdditionalTags
data.BindingKeys = bindingKeys
data.Path, _, _ = config.resolvePath(utils) // ignore error here, telemetry problems should fail the build
data.Path, _, _ = config.resolvePath(utils) // ignore error here, telemetry problems should not fail the build
configKeys := data.BuildEnv.KeysFromConfig
overallKeys := data.BuildEnv.KeysOverall
@ -334,6 +335,9 @@ func addConfigTelemetryData(utils cnbutils.BuildUtils, data *cnbBuildTelemetryDa
data.BuildEnv.KeysFromConfig = configKeys
data.BuildEnv.KeysOverall = overallKeys
buildTool, _ := getBuildToolFromStageConfig("cnbBuild") // ignore error here, telemetry problems should not fail the build
data.BuildTool = buildTool
data.Buildpacks.FromConfig = privacy.FilterBuildpacks(config.Buildpacks)
}

View File

@ -76,7 +76,6 @@ func ConfigCommand() *cobra.Command {
}
func getDockerImageValue(stepName string) (string, error) {
configOptions.contextConfig = true
configOptions.stepName = stepName
stepConfig, err := getConfig()
@ -93,38 +92,60 @@ func getDockerImageValue(stepName string) (string, error) {
return dockerImageValue, nil
}
func getBuildToolFromStageConfig(stepName string) (string, error) {
configOptions.contextConfig = true
configOptions.stepName = stepName
stageConfig, err := getStageConfig()
if err != nil {
return "", err
}
buildTool, ok := stageConfig.Config["buildTool"].(string)
if !ok {
log.Entry().Infof("Config value of %v to compare with is not a string", stageConfig.Config["buildTool"])
}
return buildTool, nil
}
func getStageConfig() (config.StepConfig, error) {
myConfig := config.Config{}
stepConfig := config.StepConfig{}
projectConfigFile := getProjectConfigFile(GeneralConfig.CustomConfig)
customConfig, err := configOptions.openFile(projectConfigFile, GeneralConfig.GitHubAccessTokens)
if err != nil {
if !os.IsNotExist(err) {
return stepConfig, errors.Wrapf(err, "config: open configuration file '%v' failed", projectConfigFile)
}
customConfig = nil
}
defaultConfig := []io.ReadCloser{}
for _, f := range GeneralConfig.DefaultConfig {
fc, err := configOptions.openFile(f, GeneralConfig.GitHubAccessTokens)
// only create error for non-default values
if err != nil && f != ".pipeline/defaults.yaml" {
return stepConfig, errors.Wrapf(err, "config: getting defaults failed: '%v'", f)
}
if err == nil {
defaultConfig = append(defaultConfig, fc)
}
}
return myConfig.GetStageConfig(GeneralConfig.ParametersJSON, customConfig, defaultConfig, GeneralConfig.IgnoreCustomDefaults, configOptions.stageConfigAcceptedParameters, GeneralConfig.StageName)
}
func getConfig() (config.StepConfig, error) {
var myConfig config.Config
var stepConfig config.StepConfig
var err error
if configOptions.stageConfig {
projectConfigFile := getProjectConfigFile(GeneralConfig.CustomConfig)
customConfig, err := configOptions.openFile(projectConfigFile, GeneralConfig.GitHubAccessTokens)
if err != nil {
if !os.IsNotExist(err) {
return stepConfig, errors.Wrapf(err, "config: open configuration file '%v' failed", projectConfigFile)
}
customConfig = nil
}
defaultConfig := []io.ReadCloser{}
for _, f := range GeneralConfig.DefaultConfig {
fc, err := configOptions.openFile(f, GeneralConfig.GitHubAccessTokens)
// only create error for non-default values
if err != nil && f != ".pipeline/defaults.yaml" {
return stepConfig, errors.Wrapf(err, "config: getting defaults failed: '%v'", f)
}
if err == nil {
defaultConfig = append(defaultConfig, fc)
}
}
stepConfig, err = myConfig.GetStageConfig(GeneralConfig.ParametersJSON, customConfig, defaultConfig, GeneralConfig.IgnoreCustomDefaults, configOptions.stageConfigAcceptedParameters, GeneralConfig.StageName)
stepConfig, err = getStageConfig()
if err != nil {
return stepConfig, errors.Wrap(err, "getting stage config failed")
}
} else {
log.Entry().Infof("Printing stepName %s", configOptions.stepName)
if GeneralConfig.MetaDataResolver == nil {