Skip to content

Commit

Permalink
Fix regex used to retrieve report (#12625)
Browse files Browse the repository at this point in the history
* Strip timestamps before searching report string

* Move regex up, to match reprotRegex

* Fix parsing build report

* Add debug logs, cean up code

* Fix regex that search for builder report
  • Loading branch information
KacperMalachowski authored Jan 31, 2025
1 parent 6c2e50b commit b15f4e8
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
1 change: 1 addition & 0 deletions cmd/image-builder/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,7 @@ func buildInADO(o options) error {
fmt.Printf("ADO pipeline image build logs:\n%s", logs)
}

fmt.Println("Getting build report.")
// Parse the build report from the ADO pipeline run logs.
buildReport, err = imagebuilder.NewBuildReportFromLogs(logs)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions pkg/imagebuilder/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

// reportRegex is a regular expression that matches the image build report
var (
reportRegex = regexp.MustCompile(`(?s)---IMAGE BUILD REPORT---\n(.*)\n---END OF IMAGE BUILD REPORT---`)
reportRegex = regexp.MustCompile(`(?s)---IMAGE BUILD REPORT---(.*)---END OF IMAGE BUILD REPORT---`)

timestampRegex = regexp.MustCompile(`\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d+Z\s`)
)
Expand Down Expand Up @@ -50,7 +50,7 @@ func NewBuildReportFromLogs(log string) (*BuildReport, error) {
// Find the report in the log
matches := reportRegex.FindStringSubmatch(log)
if len(matches) < 2 {
return nil, fmt.Errorf("no image build report found in log")
return nil, fmt.Errorf("failed to find image build report in log")
}

// Parse the report data
Expand Down

0 comments on commit b15f4e8

Please sign in to comment.