1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2024-12-14 11:03:09 +02:00
sap-jenkins-library/cmd/gradleExecuteBuild.go
Eugene Kortelyov 4d787ded6d
gradleExecuteBuild initial commit (#3337)
* gradleExecuteBuild initial commit

* fmt fixes for metadata_generated

* flow updates, some tests were added

* add gradle path alias, add stage scope to task parameter

Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
2021-12-22 15:34:36 +01:00

51 lines
1.4 KiB
Go

package cmd
import (
"github.com/SAP/jenkins-library/pkg/command"
"github.com/SAP/jenkins-library/pkg/gradle"
"github.com/SAP/jenkins-library/pkg/log"
"github.com/SAP/jenkins-library/pkg/piperutils"
"github.com/SAP/jenkins-library/pkg/telemetry"
)
type gradleExecuteBuildUtils interface {
command.ExecRunner
FileExists(filename string) (bool, error)
}
type gradleExecuteBuildUtilsBundle struct {
*command.Command
*piperutils.Files
}
func newGradleExecuteBuildUtils() gradleExecuteBuildUtils {
utils := gradleExecuteBuildUtilsBundle{
Command: &command.Command{},
Files: &piperutils.Files{},
}
utils.Stdout(log.Writer())
utils.Stderr(log.Writer())
return &utils
}
func gradleExecuteBuild(config gradleExecuteBuildOptions, telemetryData *telemetry.CustomData) {
utils := newGradleExecuteBuildUtils()
fileUtils := &piperutils.Files{}
err := runGradleExecuteBuild(&config, telemetryData, utils, fileUtils)
if err != nil {
log.Entry().WithError(err).Fatal("step execution failed: %w", err)
}
}
func runGradleExecuteBuild(config *gradleExecuteBuildOptions, telemetryData *telemetry.CustomData, utils gradleExecuteBuildUtils, fileUtils piperutils.FileUtils) error {
opt := &gradle.ExecuteOptions{BuildGradlePath: config.Path, Task: config.Task}
_, err := gradle.Execute(opt, utils, fileUtils)
if err != nil {
log.Entry().WithError(err).Errorln("build.gradle execution was failed: %w", err)
return err
}
return nil
}