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
Siarhei Pazdniakou d519966fe5
feat(gradleExecuteBuild): publish (upload to staging) (#3662)
* gradle publish

* Fix gradle utils

* Added unit test

* Add descriptions for parameters

* Added unit tests

* fix publish init script template

* fix artifactId and groupId

* fix project path

Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
2022-04-14 14:59:09 +02:00

68 lines
1.9 KiB
Go

package cmd
import (
"fmt"
"net/http"
"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
piperutils.FileUtils
DownloadFile(url, filename string, header http.Header, cookies []*http.Cookie) error
}
type gradleExecuteBuildUtilsBundle struct {
*command.Command
*piperutils.Files
}
func (g *gradleExecuteBuildUtilsBundle) DownloadFile(url, filename string, header http.Header, cookies []*http.Cookie) error {
return fmt.Errorf("not implemented")
}
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()
err := runGradleExecuteBuild(&config, telemetryData, utils)
if err != nil {
log.Entry().WithError(err).Fatalf("step execution failed: %v", err)
}
}
func runGradleExecuteBuild(config *gradleExecuteBuildOptions, telemetryData *telemetry.CustomData, utils gradleExecuteBuildUtils) error {
opt := &gradle.ExecuteOptions{
BuildGradlePath: config.Path,
Task: config.Task,
CreateBOM: config.CreateBOM,
Publish: config.Publish,
RepositoryURL: config.RepositoryURL,
RepositoryPassword: config.RepositoryPassword,
RepositoryUsername: config.RepositoryUsername,
ArtifactVersion: config.ArtifactVersion,
ArtifactGroupID: config.ArtifactGroupID,
ArtifactID: config.ArtifactID,
}
if err := gradle.Execute(opt, utils); err != nil {
log.Entry().WithError(err).Errorf("gradle build execution was failed: %v", err)
return err
}
return nil
}