Skip to content

Commit

Permalink
Merge pull request #4 from harness-community/CI-15746
Browse files Browse the repository at this point in the history
fix: [CI-15746]: Terminate when jfrog cli errors out
  • Loading branch information
Ompragash authored Jan 16, 2025
2 parents 70c7821 + bad45aa commit aea7359
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,12 @@ func main() {
// Process environment variables into the Args struct
err := envconfig.Process("", &args)
if err != nil {
logrus.Infof("Error processing environment variables: %v\n", err)
os.Exit(1)
logrus.Fatalln("Error processing environment variables:", err)
}

// Execute the main functionality of the program
if err := Exec(context.Background(), args); err != nil {
logrus.Infof("Error: %v\n", err)
os.Exit(1)
logrus.Fatalln("Error:", err)
}
}

Expand All @@ -76,7 +74,7 @@ func Exec(ctx context.Context, args Args) error {
// Parse the Docker image to extract repository, image name, and tag
repo, imageName, imageTag, err := parseDockerImage(args.DockerImage)
if err != nil {
logrus.Errorf("error parsing Docker image: %v", err)
logrus.Fatalln("error parsing Docker image:", err)
}

// Sanitize the URL for JFrog
Expand All @@ -103,15 +101,15 @@ func Exec(ctx context.Context, args Args) error {
// Create a JSON file to hold the query
queryFile, err := os.Create("query.json")
if err != nil {
logrus.Errorf("error creating query.json file: %v", err)
logrus.Fatalln("error creating query.json file:", err)
}
defer queryFile.Close()

// Encode the query into the JSON file
encoder := json.NewEncoder(queryFile)
encoder.SetIndent("", " ")
if err := encoder.Encode(query); err != nil {
logrus.Errorf("error encoding query to query.json: %v", err)
logrus.Fatalln("failed to encode query to query.json:", err)
}

// Prepare the command to search for the manifest file in JFrog
Expand All @@ -124,7 +122,7 @@ func Exec(ctx context.Context, args Args) error {
// Run the command and capture the output
output, err := runCommandAndCaptureOutput(cmdArgs)
if err != nil {
logrus.Errorf("error executing jfrog rt s command: %v", err)
logrus.Fatalln("error executing jfrog rt s command: ", err)
}

// Extract the SHA256 hash from the command output
Expand Down Expand Up @@ -159,15 +157,15 @@ func Exec(ctx context.Context, args Args) error {

// Execute the build creation command
if err := runCommand(cmdArgs); err != nil {
logrus.Errorf("error executing jfrog rt build-docker-create command: %v", err)
logrus.Fatalln("error executing jfrog rt build-docker-create command:", err)
}

// If Git information is available, add it to the build info
logrus.Info("Setting Git Properties")
if args.RepoURL != "" && args.BranchName != "" && args.CommitSha != "" {
cmdArgs = []string{"jfrog", "rt", "build-add-git", args.BuildName, args.BuildNumber, args.GitPath}
if err := runCommand(cmdArgs); err != nil {
logrus.Errorf("error executing jfrog rt build-add-git command: %v", err)
logrus.Fatalln("error executing jfrog rt build-add-git command:", err)
}
}

Expand All @@ -181,7 +179,7 @@ func Exec(ctx context.Context, args Args) error {

// Execute the build publish command
if err := runCommand(cmdArgs); err != nil {
logrus.Errorf("error executing jfrog rt build-publish command: %v", err)
logrus.Fatalln("error executing jfrog rt build-publish command:", err)
}

return nil
Expand Down
Empty file modified scripts/build.sh
100644 → 100755
Empty file.

0 comments on commit aea7359

Please sign in to comment.