From a76ad02144b9e5d2ca5910b527ab0404215245b3 Mon Sep 17 00:00:00 2001 From: felipecruz91 Date: Tue, 7 Sep 2021 09:00:38 +0200 Subject: [PATCH] Fix nodejs agent name --- README.md | 5 +++-- internal/test/nodejs-agent-name/Jenkinsfile | 13 +++++++++++++ internal/test/nodejs-agent-name/golden/Jenkinsfile | 13 +++++++++++++ internal/test/nodejs-agent-name/out/.keep | 0 .../stage-rollout-multi-line/golden/Jenkinsfile | 2 +- .../stage-rollout-single-line/golden/Jenkinsfile | 2 +- replacer.go | 11 +++++++++-- replacer_test.go | 8 ++++++++ 8 files changed, 48 insertions(+), 6 deletions(-) create mode 100644 internal/test/nodejs-agent-name/Jenkinsfile create mode 100644 internal/test/nodejs-agent-name/golden/Jenkinsfile create mode 100644 internal/test/nodejs-agent-name/out/.keep diff --git a/README.md b/README.md index 35211b3..a06bace 100644 --- a/README.md +++ b/README.md @@ -7,10 +7,10 @@ This is a Golang CLI to convert the a Jenkinsfile based on 3.x to 4.x based on t ## Download -Target a specific version and platform for the binary. For version `v0.1.0` and linux, you would: +Target a specific version and platform for the binary. For version `v0.1.2` and linux, you would: ```cli - curl -L https://github.com/opendevstack/ods-jenkinsfile-converter/releases/download/v0.1.0/converter -o converter + curl -L https://github.com/opendevstack/ods-jenkinsfile-converter/releases/download/v0.1.2/converter -o converter sudo mv converter /usr/local/bin ``` @@ -62,6 +62,7 @@ This tool will carry out the following changes in an ODS 3.x Jenkinsfile: - [X] Update `@Library('ods-jenkins-shared-library@3.x') _` to `@Library('ods-jenkins-shared-library@4.x') _` - [X] Point to agent images with the 4.x tag, e.g. change imageStreamTag: `ods/jenkins-agent-golang:3.x` to imageStreamTag: `ods/jenkins-agent-golang:4.x`. +- [X] NodeJS agent name is going to change in ODS 4. From `jenkins-agent-nodejs10-angular` to `jenkins-agent-nodejs12`. - [X] `odsComponentStageImportOpenShiftImageOrElse` has been deprecated, and is now aliased to the new method, `odsComponentFindOpenShiftImageOrElse`. - [X] `odsComponentStageRolloutOpenShiftDeployment` rolls out all deployment resources together now. If you had multiple DeploymentConfig resources previously, you had to target each one by specifying the config option resourceName. This is no longer possible - instead the stage iterates over all DeploymentConfig resources with the component label (app=${projectId}-${componentId}). Changes must be made to pipelines that have multiple deployments, such as components based on the ds-jupyter-notebook and ds-rshiny quickstarter. diff --git a/internal/test/nodejs-agent-name/Jenkinsfile b/internal/test/nodejs-agent-name/Jenkinsfile new file mode 100644 index 0000000..3fac9dc --- /dev/null +++ b/internal/test/nodejs-agent-name/Jenkinsfile @@ -0,0 +1,13 @@ +// See https://www.opendevstack.org/ods-documentation/ for usage and customization. + +@Library('ods-jenkins-shared-library@3.x') _ + +odsComponentPipeline( + imageStreamTag: 'ods/jenkins-agent-nodejs10-angular:3.0.0', + branchToEnvironmentMapping: [ + 'master': 'dev', + 'release/': 'test', + ] +) { context -> + // nothing... +} diff --git a/internal/test/nodejs-agent-name/golden/Jenkinsfile b/internal/test/nodejs-agent-name/golden/Jenkinsfile new file mode 100644 index 0000000..6e13a86 --- /dev/null +++ b/internal/test/nodejs-agent-name/golden/Jenkinsfile @@ -0,0 +1,13 @@ +// See https://www.opendevstack.org/ods-documentation/ for usage and customization. + +@Library('ods-jenkins-shared-library@4.x') _ + +odsComponentPipeline( + imageStreamTag: 'ods/jenkins-agent-nodejs12:4.x', + branchToEnvironmentMapping: [ + 'master': 'dev', + 'release/': 'test', + ] +) { context -> + // nothing... +} diff --git a/internal/test/nodejs-agent-name/out/.keep b/internal/test/nodejs-agent-name/out/.keep new file mode 100644 index 0000000..e69de29 diff --git a/internal/test/stage-rollout-multi-line/golden/Jenkinsfile b/internal/test/stage-rollout-multi-line/golden/Jenkinsfile index 5b80d3a..dd62a6e 100644 --- a/internal/test/stage-rollout-multi-line/golden/Jenkinsfile +++ b/internal/test/stage-rollout-multi-line/golden/Jenkinsfile @@ -7,7 +7,7 @@ node { } odsComponentPipeline( - imageStreamTag: 'ods/jenkins-agent-maven:4.0.0', + imageStreamTag: 'ods/jenkins-agent-maven:4.x', branchToEnvironmentMapping: [ 'master': 'dev', 'release/': 'test', diff --git a/internal/test/stage-rollout-single-line/golden/Jenkinsfile b/internal/test/stage-rollout-single-line/golden/Jenkinsfile index e7eff26..f4cdad8 100644 --- a/internal/test/stage-rollout-single-line/golden/Jenkinsfile +++ b/internal/test/stage-rollout-single-line/golden/Jenkinsfile @@ -3,7 +3,7 @@ @Library('ods-jenkins-shared-library@4.x') _ odsComponentPipeline( - imageStreamTag: 'ods/jenkins-agent-base:4.0.0', + imageStreamTag: 'ods/jenkins-agent-base:4.x', openshiftBuildTimeout: 30, branchToEnvironmentMapping: [ 'master': 'dev', diff --git a/replacer.go b/replacer.go index e522f54..399865e 100644 --- a/replacer.go +++ b/replacer.go @@ -39,8 +39,15 @@ func replaceLibrary(content string) string { } func replaceAgentImages(content string) string { - re := regexp.MustCompile(`'ods\/jenkins-agent-(.*):(\d).(.*)'`) - return re.ReplaceAllString(content, "'ods/jenkins-agent-$1:4.$3'") + 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'") + } + + return re.ReplaceAllString(content, "'ods/jenkins-agent-$1:4.x'") } func replaceComponentStageImport(content string) string { diff --git a/replacer_test.go b/replacer_test.go index 42b3e77..009845d 100644 --- a/replacer_test.go +++ b/replacer_test.go @@ -32,6 +32,14 @@ func TestReplace(t *testing.T) { }, want: readFile("internal/test/stage-rollout-multi-line/golden/Jenkinsfile"), }, + { + name: "NodeJS agent name change", + args: args{ + inputFile: "internal/test/nodejs-agent-name/Jenkinsfile", + convertedFile: "internal/test/nodejs-agent-name/out/Jenkinsfile", + }, + want: readFile("internal/test/nodejs-agent-name/golden/Jenkinsfile"), + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) {