Skip to content

Commit

Permalink
Merge pull request #4 from opendevstack/hotfix/nodejs-agent-name
Browse files Browse the repository at this point in the history
Fix nodejs agent name
  • Loading branch information
felipecruz91 authored Sep 7, 2021
2 parents dad942c + 6c226c5 commit 6a04b1f
Show file tree
Hide file tree
Showing 8 changed files with 123 additions and 81 deletions.
155 changes: 78 additions & 77 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,77 +1,78 @@
# ods-jenkinsfile-converter
[![build](https://github.com/opendevstack/ods-jenkinsfile-converter/actions/workflows/build.yml/badge.svg)](https://github.com/opendevstack/ods-jenkinsfile-converter/actions/workflows/build.yml)

## Introduction

This is a Golang CLI to convert the a Jenkinsfile based on 3.x to 4.x based on the [official required changes](https://www.opendevstack.org/ods-documentation/opendevstack/4.x/update-guides/4x.html).

## Download

Target a specific version and platform for the binary. For version `v0.1.1` and linux, you would:

```cli
curl -L https://github.com/opendevstack/ods-jenkinsfile-converter/releases/download/v0.1.1/converter -o converter
sudo mv converter /usr/local/bin
```

For other platforms like Windows or MacOS choose the binary from the links [here](https://github.com/opendevstack/ods-jenkinsfile-converter/releases).

## Usage

Given a Jenkinsfile based on 3.x, to preview the changes that will result when migrating to ODS 4.x, use the `--dry-run` flag

```cli
converter -filename="examples/machine-learning/Jenkinsfile" --dry-run
```

or to persist the changes in an output file

```cli
converter -filename="examples/machine-learning/Jenkinsfile" -out "out/Jenkinsfile"
```

The converted Jenkinsfile with the ODS 4.x adopted changes will be under the [out](./out) directory:

```cli
cat out/Jenkinsfile
```

## Building it locally

Generate the binaries under [bin](./bin)

```cli
make all
```

You can run the binary for your platform. To preview the changes that will be done, use the `--dry-run` flag

```cli
./bin/converter -filename="examples/machine-learning/Jenkinsfile" --dry-run
```

## Run it with `Go`

```cli
go run . -filename="examples/machine-learning/Jenkinsfile" -out "out/Jenkinsfile"
```

## Features

This tool will carry out the following changes in an ODS 3.x Jenkinsfile:

- [X] Update `@Library('[email protected]') _` to `@Library('[email protected]') _`
- [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` or imageStreamTag: `ods/jenkins-agent-golang:3.0.0` to imageStreamTag: `ods/jenkins-agent-golang:4.0.0`.
- [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.

For instance, the following must be changed from:

`odsComponentStageRolloutOpenShiftDeployment(context, [resourceName: "${context.componentId}-auth-proxy"])`

to:

`odsComponentStageRolloutOpenShiftDeployment(context)`

## Limitations
- Only Jenkinsfiles from 3.x are supported.
# ods-jenkinsfile-converter
[![build](https://github.com/opendevstack/ods-jenkinsfile-converter/actions/workflows/build.yml/badge.svg)](https://github.com/opendevstack/ods-jenkinsfile-converter/actions/workflows/build.yml)

## Introduction

This is a Golang CLI to convert the a Jenkinsfile based on 3.x to 4.x based on the [official required changes](https://www.opendevstack.org/ods-documentation/opendevstack/4.x/update-guides/4x.html).

## Download

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.2/converter -o converter
sudo mv converter /usr/local/bin
```

For other platforms like Windows or MacOS choose the binary from the links [here](https://github.com/opendevstack/ods-jenkinsfile-converter/releases).

## Usage

Given a Jenkinsfile based on 3.x, to preview the changes that will result when migrating to ODS 4.x, use the `--dry-run` flag

```cli
converter -filename="examples/machine-learning/Jenkinsfile" --dry-run
```

or to persist the changes in an output file

```cli
converter -filename="examples/machine-learning/Jenkinsfile" -out "out/Jenkinsfile"
```

The converted Jenkinsfile with the ODS 4.x adopted changes will be under the [out](./out) directory:

```cli
cat out/Jenkinsfile
```

## Building it locally

Generate the binaries under [bin](./bin)

```cli
make all
```

You can run the binary for your platform. To preview the changes that will be done, use the `--dry-run` flag

```cli
./bin/converter -filename="examples/machine-learning/Jenkinsfile" --dry-run
```

## Run it with `Go`

```cli
go run . -filename="examples/machine-learning/Jenkinsfile" -out "out/Jenkinsfile"
```

## Features

This tool will carry out the following changes in an ODS 3.x Jenkinsfile:

- [X] Update `@Library('[email protected]') _` to `@Library('[email protected]') _`
- [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.

For instance, the following must be changed from:

`odsComponentStageRolloutOpenShiftDeployment(context, [resourceName: "${context.componentId}-auth-proxy"])`

to:

`odsComponentStageRolloutOpenShiftDeployment(context)`

## Limitations
- Only Jenkinsfiles from 3.x are supported.
13 changes: 13 additions & 0 deletions internal/test/nodejs-agent-name/Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// See https://www.opendevstack.org/ods-documentation/ for usage and customization.

@Library('[email protected]') _

odsComponentPipeline(
imageStreamTag: 'ods/jenkins-agent-nodejs10-angular:3.0.0',
branchToEnvironmentMapping: [
'master': 'dev',
'release/': 'test',
]
) { context ->
// nothing...
}
13 changes: 13 additions & 0 deletions internal/test/nodejs-agent-name/golden/Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// See https://www.opendevstack.org/ods-documentation/ for usage and customization.

@Library('[email protected]') _

odsComponentPipeline(
imageStreamTag: 'ods/jenkins-agent-nodejs12:4.x',
branchToEnvironmentMapping: [
'master': 'dev',
'release/': 'test',
]
) { context ->
// nothing...
}
Empty file.
2 changes: 1 addition & 1 deletion internal/test/stage-rollout-multi-line/golden/Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion internal/test/stage-rollout-single-line/golden/Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
@Library('[email protected]') _

odsComponentPipeline(
imageStreamTag: 'ods/jenkins-agent-base:4.0.0',
imageStreamTag: 'ods/jenkins-agent-base:4.x',
openshiftBuildTimeout: 30,
branchToEnvironmentMapping: [
'master': 'dev',
Expand Down
11 changes: 9 additions & 2 deletions replacer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 8 additions & 0 deletions replacer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 6a04b1f

Please sign in to comment.