-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix replaceAgentimages from panicking, adjust the implementation of t…
…hat method and create different unit tests suites
- Loading branch information
Showing
2 changed files
with
109 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,16 +38,25 @@ func replaceLibrary(content string) string { | |
return strings.Replace(content, "@Library('[email protected]') _", "@Library('[email protected]') _", -1) | ||
} | ||
|
||
// replaceAgentImages is a method that changes images which follows the pattern "ods/jenkins-agent*". | ||
//It considers single, double quotes, and multiple images in the same Jenkinsfile without panicking. | ||
func replaceAgentImages(content string) string { | ||
re := regexp.MustCompile(`'ods/jenkins-agent-(.*):.*'`) | ||
|
||
matches := re.FindAllStringSubmatch(content, -1) | ||
fmt.Println(matches[0][1]) | ||
if string(matches[0][1]) == "nodejs10-angular" { | ||
return re.ReplaceAllString(content, "'ods/jenkins-agent-nodejs12:4.x'") | ||
} | ||
re := regexp.MustCompile(`(['"]{1}ods/jenkins-agent-)(.*):(.*)(['"]{1})`) | ||
lines := strings.Split(content, "\n") | ||
|
||
return re.ReplaceAllString(content, "'ods/jenkins-agent-$1:4.x'") | ||
for idx, line := range lines { | ||
if match := re.FindStringSubmatch(line); match != nil { | ||
lines[idx] = func(s1 string, s2 []string) string { | ||
if string(s2[2]) == "nodejs10-angular" { | ||
return re.ReplaceAllString(line, fmt.Sprintf("%s%s%s", s2[1], "nodejs12:4.x", s2[4])) | ||
} else { | ||
return re.ReplaceAllString(line, fmt.Sprintf("%s%s%s%s", s2[1], s2[2], ":4.x", s2[4])) | ||
} | ||
}(line, match) | ||
} | ||
} | ||
return strings.Join(lines, "\n") | ||
} | ||
|
||
func replaceComponentStageImport(content string) string { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters