1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2025-02-21 19:48:53 +02:00

Add maven native-like build workaround for detect (#4712)

* added-native-like-build

* pom-path-uncommented

* Run install only for maven

* Added log

* debug

* Print config params

* Added pipeline env

* Added parameter to specify path to pom.xml

* Returned condition

* Added logging of config in verbose mode

---------

Co-authored-by: Andrei Kireev <a-kireev1989@mail.ru>
Co-authored-by: Andrei Kireev <andrei.kireev@sap.com>
This commit is contained in:
Dmitrii Pavlukhin 2024-01-16 00:50:22 +03:00 committed by GitHub
parent 9074822e57
commit 808b21fa79
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 77 additions and 0 deletions

View File

@ -140,6 +140,9 @@ func detectExecuteScan(config detectExecuteScanOptions, _ *telemetry.CustomData,
log.Entry().WithError(err).Warning("Failed to get GitHub client")
}
// Log config for debug purpose
logConfigInVerboseMode(config)
if config.PrivateModules != "" && config.PrivateModulesGitToken != "" {
//configuring go private packages
if err := golang.PrepareGolangPrivatePackages("detectExecuteStep", config.PrivateModules, config.PrivateModulesGitToken); err != nil {
@ -185,6 +188,17 @@ func runDetect(ctx context.Context, config detectExecuteScanOptions, utils detec
}
}
if config.BuildMaven {
log.Entry().Infof("running Maven Build")
mavenConfig := setMavenConfig(config)
mavenUtils := maven.NewUtilsBundle()
err := runMavenBuild(&mavenConfig, nil, mavenUtils, &mavenBuildCommonPipelineEnvironment{})
if err != nil {
return err
}
}
blackduckSystem := newBlackduckSystem(config)
args := []string{"./detect.sh"}
@ -895,3 +909,28 @@ func createToolRecordDetect(utils detectUtils, workspace string, config detectEx
}
return record.GetFileName(), nil
}
func setMavenConfig(config detectExecuteScanOptions) mavenBuildOptions {
mavenConfig := mavenBuildOptions{
PomPath: config.PomPath,
Flatten: true,
Verify: false,
ProjectSettingsFile: config.ProjectSettingsFile,
GlobalSettingsFile: config.GlobalSettingsFile,
M2Path: config.M2Path,
LogSuccessfulMavenTransfers: false,
CreateBOM: false,
CustomTLSCertificateLinks: config.CustomTLSCertificateLinks,
Publish: false,
}
return mavenConfig
}
func logConfigInVerboseMode(config detectExecuteScanOptions) {
config.Token = "********"
config.GithubToken = "********"
config.PrivateModulesGitToken = "********"
debugLog, _ := json.Marshal(config)
log.Entry().Debugf("Detect configuration: %v", string(debugLog))
}

View File

@ -40,6 +40,8 @@ type detectExecuteScanOptions struct {
GlobalSettingsFile string `json:"globalSettingsFile,omitempty"`
M2Path string `json:"m2Path,omitempty"`
InstallArtifacts bool `json:"installArtifacts,omitempty"`
BuildMaven bool `json:"buildMaven,omitempty"`
PomPath string `json:"pomPath,omitempty"`
IncludedPackageManagers []string `json:"includedPackageManagers,omitempty"`
ExcludedPackageManagers []string `json:"excludedPackageManagers,omitempty"`
MavenExcludedScopes []string `json:"mavenExcludedScopes,omitempty"`
@ -284,6 +286,8 @@ func addDetectExecuteScanFlags(cmd *cobra.Command, stepConfig *detectExecuteScan
cmd.Flags().StringVar(&stepConfig.GlobalSettingsFile, "globalSettingsFile", os.Getenv("PIPER_globalSettingsFile"), "Path or url to the mvn settings file that should be used as global settings file")
cmd.Flags().StringVar(&stepConfig.M2Path, "m2Path", os.Getenv("PIPER_m2Path"), "Path to the location of the local repository that should be used.")
cmd.Flags().BoolVar(&stepConfig.InstallArtifacts, "installArtifacts", false, "If enabled, it will install all artifacts to the local maven repository to make them available before running detect. This is required if any maven module has dependencies to other modules in the repository and they were not installed before.")
cmd.Flags().BoolVar(&stepConfig.BuildMaven, "buildMaven", false, "Experiment parameter for maven multi-modules projects building")
cmd.Flags().StringVar(&stepConfig.PomPath, "pomPath", `pom.xml`, "Path to the pom file which should be installed including all children.")
cmd.Flags().StringSliceVar(&stepConfig.IncludedPackageManagers, "includedPackageManagers", []string{}, "The package managers that need to be included for this scan. Providing the package manager names with this parameter will ensure that the build descriptor file of that package manager will be searched in the scan folder For the complete list of possible values for this parameter, please refer [Synopsys detect documentation](https://community.synopsys.com/s/document-item?bundleId=integrations-detect&topicId=properties%2Fconfiguration%2Fdetector.html&_LANG=enus&anchor=detector-types-included-advanced)")
cmd.Flags().StringSliceVar(&stepConfig.ExcludedPackageManagers, "excludedPackageManagers", []string{}, "The package managers that need to be excluded for this scan. Providing the package manager names with this parameter will ensure that the build descriptor file of that package manager will be ignored in the scan folder For the complete list of possible values for this parameter, please refer [Synopsys detect documentation](https://community.synopsys.com/s/document-item?bundleId=integrations-detect&topicId=properties%2Fconfiguration%2Fdetector.html&_LANG=enus&anchor=detector-types-excluded-advanced)")
cmd.Flags().StringSliceVar(&stepConfig.MavenExcludedScopes, "mavenExcludedScopes", []string{}, "The maven scopes that need to be excluded from the scan. For example, setting the value 'test' will exclude all components which are defined with a test scope in maven")
@ -510,6 +514,24 @@ func detectExecuteScanMetadata() config.StepData {
Aliases: []config.Alias{},
Default: false,
},
{
Name: "buildMaven",
ResourceRef: []config.ResourceReference{},
Scope: []string{"STEPS", "STAGES", "PARAMETERS"},
Type: "bool",
Mandatory: false,
Aliases: []config.Alias{},
Default: false,
},
{
Name: "pomPath",
ResourceRef: []config.ResourceReference{},
Scope: []string{"STEPS"},
Type: "string",
Mandatory: false,
Aliases: []config.Alias{},
Default: `pom.xml`,
},
{
Name: "includedPackageManagers",
ResourceRef: []config.ResourceReference{},

View File

@ -248,6 +248,22 @@ spec:
- STEPS
- STAGES
- PARAMETERS
- name: buildMaven
type: bool
default: false
description:
"Experiment parameter for maven multi-modules projects building"
scope:
- STEPS
- STAGES
- PARAMETERS
- name: pomPath
type: string
description: Path to the pom file which should be installed including all children.
scope:
- STEPS
mandatory: false
default: pom.xml
- name: includedPackageManagers
description:
"The package managers that need to be included for this scan. Providing the package manager names with this parameter will ensure that the build descriptor file of that package manager will be searched in the scan folder