mirror of
https://github.com/SAP/jenkins-library.git
synced 2025-01-16 05:16:08 +02:00
feat(detectExecuteScan) Added npm install step for detectExectueScan (#4949)
* Added npm install step for detectExectueScan
This commit is contained in:
parent
df1db9eed7
commit
e2a5b0928a
@ -20,6 +20,7 @@ import (
|
|||||||
piperhttp "github.com/SAP/jenkins-library/pkg/http"
|
piperhttp "github.com/SAP/jenkins-library/pkg/http"
|
||||||
"github.com/SAP/jenkins-library/pkg/log"
|
"github.com/SAP/jenkins-library/pkg/log"
|
||||||
"github.com/SAP/jenkins-library/pkg/maven"
|
"github.com/SAP/jenkins-library/pkg/maven"
|
||||||
|
"github.com/SAP/jenkins-library/pkg/npm"
|
||||||
"github.com/SAP/jenkins-library/pkg/orchestrator"
|
"github.com/SAP/jenkins-library/pkg/orchestrator"
|
||||||
"github.com/SAP/jenkins-library/pkg/piperutils"
|
"github.com/SAP/jenkins-library/pkg/piperutils"
|
||||||
"github.com/SAP/jenkins-library/pkg/reporting"
|
"github.com/SAP/jenkins-library/pkg/reporting"
|
||||||
@ -213,6 +214,22 @@ func runDetect(ctx context.Context, config detectExecuteScanOptions, utils detec
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Install NPM dependencies
|
||||||
|
if config.InstallNPM {
|
||||||
|
log.Entry().Debugf("running npm install")
|
||||||
|
npmExecutor := npm.NewExecutor(npm.ExecutorOptions{DefaultNpmRegistry: config.DefaultNpmRegistry})
|
||||||
|
|
||||||
|
buildDescriptorList := config.BuildDescriptorList
|
||||||
|
if len(buildDescriptorList) == 0 {
|
||||||
|
buildDescriptorList = []string{"package.json"}
|
||||||
|
}
|
||||||
|
|
||||||
|
err := npmExecutor.InstallAllDependencies(buildDescriptorList)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// for MTA
|
// for MTA
|
||||||
if config.BuildMTA {
|
if config.BuildMTA {
|
||||||
log.Entry().Infof("running MTA Build")
|
log.Entry().Infof("running MTA Build")
|
||||||
|
@ -42,6 +42,9 @@ type detectExecuteScanOptions struct {
|
|||||||
InstallArtifacts bool `json:"installArtifacts,omitempty"`
|
InstallArtifacts bool `json:"installArtifacts,omitempty"`
|
||||||
BuildMaven bool `json:"buildMaven,omitempty"`
|
BuildMaven bool `json:"buildMaven,omitempty"`
|
||||||
BuildMTA bool `json:"buildMTA,omitempty"`
|
BuildMTA bool `json:"buildMTA,omitempty"`
|
||||||
|
InstallNPM bool `json:"installNPM,omitempty"`
|
||||||
|
DefaultNpmRegistry string `json:"defaultNpmRegistry,omitempty"`
|
||||||
|
BuildDescriptorList []string `json:"buildDescriptorList,omitempty"`
|
||||||
EnableDiagnostics bool `json:"enableDiagnostics,omitempty"`
|
EnableDiagnostics bool `json:"enableDiagnostics,omitempty"`
|
||||||
GenerateReportsForEmptyProjects bool `json:"generateReportsForEmptyProjects,omitempty"`
|
GenerateReportsForEmptyProjects bool `json:"generateReportsForEmptyProjects,omitempty"`
|
||||||
MtaPlatform string `json:"mtaPlatform,omitempty"`
|
MtaPlatform string `json:"mtaPlatform,omitempty"`
|
||||||
@ -298,6 +301,9 @@ func addDetectExecuteScanFlags(cmd *cobra.Command, stepConfig *detectExecuteScan
|
|||||||
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.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().BoolVar(&stepConfig.BuildMaven, "buildMaven", false, "Experiment parameter for maven multi-modules projects building")
|
||||||
cmd.Flags().BoolVar(&stepConfig.BuildMTA, "buildMTA", false, "Experiment parameter for MTA projects building")
|
cmd.Flags().BoolVar(&stepConfig.BuildMTA, "buildMTA", false, "Experiment parameter for MTA projects building")
|
||||||
|
cmd.Flags().BoolVar(&stepConfig.InstallNPM, "installNPM", false, "Experiment parameter for downloading npm dependencies")
|
||||||
|
cmd.Flags().StringVar(&stepConfig.DefaultNpmRegistry, "defaultNpmRegistry", os.Getenv("PIPER_defaultNpmRegistry"), "URL of the npm registry to use. Defaults to https://registry.npmjs.org/")
|
||||||
|
cmd.Flags().StringSliceVar(&stepConfig.BuildDescriptorList, "buildDescriptorList", []string{}, "List of build descriptors and therefore modules for execution of the npm scripts. The elements have to be paths to the build descriptors.")
|
||||||
cmd.Flags().BoolVar(&stepConfig.EnableDiagnostics, "enableDiagnostics", false, "Parameter to enable diagnostics file generation by detect script")
|
cmd.Flags().BoolVar(&stepConfig.EnableDiagnostics, "enableDiagnostics", false, "Parameter to enable diagnostics file generation by detect script")
|
||||||
cmd.Flags().BoolVar(&stepConfig.GenerateReportsForEmptyProjects, "generateReportsForEmptyProjects", false, "If enabled, it will generate reports for empty projects. This could be useful to see the compliance reports in Sirius")
|
cmd.Flags().BoolVar(&stepConfig.GenerateReportsForEmptyProjects, "generateReportsForEmptyProjects", false, "If enabled, it will generate reports for empty projects. This could be useful to see the compliance reports in Sirius")
|
||||||
cmd.Flags().StringVar(&stepConfig.MtaPlatform, "mtaPlatform", `CF`, "The platform of the MTA project")
|
cmd.Flags().StringVar(&stepConfig.MtaPlatform, "mtaPlatform", `CF`, "The platform of the MTA project")
|
||||||
@ -552,6 +558,33 @@ func detectExecuteScanMetadata() config.StepData {
|
|||||||
Aliases: []config.Alias{},
|
Aliases: []config.Alias{},
|
||||||
Default: false,
|
Default: false,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Name: "installNPM",
|
||||||
|
ResourceRef: []config.ResourceReference{},
|
||||||
|
Scope: []string{"STEPS", "STAGES", "PARAMETERS"},
|
||||||
|
Type: "bool",
|
||||||
|
Mandatory: false,
|
||||||
|
Aliases: []config.Alias{},
|
||||||
|
Default: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "defaultNpmRegistry",
|
||||||
|
ResourceRef: []config.ResourceReference{},
|
||||||
|
Scope: []string{"PARAMETERS", "GENERAL", "STAGES", "STEPS"},
|
||||||
|
Type: "string",
|
||||||
|
Mandatory: false,
|
||||||
|
Aliases: []config.Alias{{Name: "npm/defaultNpmRegistry"}},
|
||||||
|
Default: os.Getenv("PIPER_defaultNpmRegistry"),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "buildDescriptorList",
|
||||||
|
ResourceRef: []config.ResourceReference{},
|
||||||
|
Scope: []string{"PARAMETERS", "STAGES", "STEPS"},
|
||||||
|
Type: "[]string",
|
||||||
|
Mandatory: false,
|
||||||
|
Aliases: []config.Alias{},
|
||||||
|
Default: []string{},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
Name: "enableDiagnostics",
|
Name: "enableDiagnostics",
|
||||||
ResourceRef: []config.ResourceReference{},
|
ResourceRef: []config.ResourceReference{},
|
||||||
|
@ -266,6 +266,32 @@ spec:
|
|||||||
- STEPS
|
- STEPS
|
||||||
- STAGES
|
- STAGES
|
||||||
- PARAMETERS
|
- PARAMETERS
|
||||||
|
- name: installNPM
|
||||||
|
type: bool
|
||||||
|
default: false
|
||||||
|
description:
|
||||||
|
"Experiment parameter for downloading npm dependencies"
|
||||||
|
scope:
|
||||||
|
- STEPS
|
||||||
|
- STAGES
|
||||||
|
- PARAMETERS
|
||||||
|
- name: defaultNpmRegistry
|
||||||
|
type: string
|
||||||
|
description: "URL of the npm registry to use. Defaults to https://registry.npmjs.org/"
|
||||||
|
scope:
|
||||||
|
- PARAMETERS
|
||||||
|
- GENERAL
|
||||||
|
- STAGES
|
||||||
|
- STEPS
|
||||||
|
aliases:
|
||||||
|
- name: npm/defaultNpmRegistry
|
||||||
|
- name: buildDescriptorList
|
||||||
|
type: "[]string"
|
||||||
|
description: List of build descriptors and therefore modules for execution of the npm scripts. The elements have to be paths to the build descriptors.
|
||||||
|
scope:
|
||||||
|
- PARAMETERS
|
||||||
|
- STAGES
|
||||||
|
- STEPS
|
||||||
- name: enableDiagnostics
|
- name: enableDiagnostics
|
||||||
type: bool
|
type: bool
|
||||||
default: false
|
default: false
|
||||||
|
Loading…
Reference in New Issue
Block a user