From ca7952258d167943030e03c80b2cea3bc855d313 Mon Sep 17 00:00:00 2001 From: Begona Guereca Date: Wed, 17 Aug 2022 15:13:41 -0700 Subject: [PATCH 01/28] Add custom transformer lab --- jenkins/valet-custom-transformers-lab.md | 445 +++++++++++++++++++++++ 1 file changed, 445 insertions(+) create mode 100644 jenkins/valet-custom-transformers-lab.md diff --git a/jenkins/valet-custom-transformers-lab.md b/jenkins/valet-custom-transformers-lab.md new file mode 100644 index 0000000..0f8f83e --- /dev/null +++ b/jenkins/valet-custom-transformers-lab.md @@ -0,0 +1,445 @@ +# Using Custom Transformers in a `dry-run` + +In this lab we want to do a `dry-run` of the `test_pipeline` pipeline, however, after a closer inspection, we have discovered that we will need to be customize the transformation of: + +1. Steps that are unsupported by Valet, buts are essential to our devops process. +2. Steps in which the GitHub action chosen by Valet does not meet our current needs. +3. All pipelines that have the environment variable `DB_ENGINE` must be changed to a different value: `mongodb`. +4. The self-hosted runners before were called `TeamARunner` and with the GitHub Migration they will be called `ubuntu-latest`. + +These customizations will be present in many of our company's pipelines and an automated way to apply these changes would be ideal. In this lab, we will use the `--custom-transformers` flag to change the behavior of Valet using its DSL built on top of the Ruby language. + +- [Prerequisites](#prerequisites) +- [Perform a dry-run](#perform-a-dry-run) +- [Custom transformers for an unknown step](#custom-transformers-for-unknown-step) +- [Custom transformers for an known step](#custom-transformers-for-known-step) +- [Custom transformers for environment variables](#custom-transformers-for-environment-varibales) +- [Custom transformers for runners](#custom-transformers-for-runners) +- [Next Lab](#next-lab) + +## Prerequisites + +1. Followed [steps](../jenkins#readme) to set up your codespace environment. +2. Completed the [configure lab](../jenkins/valet-configure-lab.md) +3. Completed the [dry-run lab](../jenkins/valet-dry-run-lab.md) + +## Perform a dry-run + +- Let’s run the `dry-run` command to see what information we can get from the generated action yaml. + + ```bash + gh valet dry-run jenkins --source-url http://localhost:8080/job/test_pipeline -o .tmp/jenkins/dry-run + ``` + +- Open the resulting GitHub Actions workflow by navigating to `tmp/valet/test_pipeline.yml` from the explorer + +__Click to Expand__ +
+ Actions Workflow + +```yaml +name: test_pipeline +on: + push: + paths: "*" + schedule: + - cron: 0-29/10 * * * * +env: + DISABLE_AUTH: 'true' + DB_ENGINE: sqlite +jobs: + build: + runs-on: + - self-hosted + - TeamARunner + steps: + - name: checkout + uses: actions/checkout@v2 + - name: echo message + run: echo "Database engine is ${{ env.DB_ENGINE }}" +# # This item has no matching transformer +# - sleep: +# - key: time +# value: +# isLiteral: true +# value: 80 + - name: echo message + run: echo "DISABLE_AUTH is ${{ env.DISABLE_AUTH }}" + test: + runs-on: + - self-hosted + - TeamARunner + needs: build + steps: + - name: checkout + uses: actions/checkout@v2 + - name: Publish test results + uses: EnricoMi/publish-unit-test-result-action@v1.7 + if: always() + with: + files: "**/target/*.xml" +``` + +
+ +Go back to the previous lab [Dry-run Jenkins Pipeline](../jenkins/valet-migrate-lab.md) if you need a review of the details of the dry-run. + +## Custom transformers for an unknown step + +We can see in the center of the transformed workflow that the `sleep` step was not transformed. In order for us to write a custom transformer for this we need to know the identifier. In general, the identifier will be the key of a key/value pair within the step of a Jenkinsfile, which in this case is `sleep`. This is how our custom transformer will target the correct step. + +After some research we have decided that a simple bash script will meet our needs: + + ```yaml + - name: Sleep for 30 seconds + run: sleep 30s + shell: bash + ``` + +Now that we know the final yaml needed for the transformer, we can start to write the ruby file.The custom transformers file can have any name, but it is recommended that you use an `.rb` extension so the codespaces editor knows it is a ruby file and can provide syntax highlighting. + +- Create a new file where you will put the custom transformers logic. It can have any file name, but it is recommended that you use an `.rb` extension so the codespaces editor knows it is a ruby file and can provide syntax highlighting. For this example we will call it `transformers.rb`. + +In the custom transformers file we will call the `transform` method. This is a special method that Valet exposes, that takes the identifier we determined earlier and returns a ruby hash of the final YAML for the pipeline. + +The ruby hash can be thought of as the JSON representation of the YAML we want. Valet will call that method when it encounters the identifier and pass in an `item`. The `item` is the values defined for that step in Jenkins. In this case the item is the path of the sleep command. + + ```ruby + transform "sleep" do |item| + { + "name": "Sleep for 30 seconds", + "run": "sleep 30s", + "shell": "bash" + } + end + ``` + +Let’s run the `dry-run` command again to see if our custom transformer worked. + +```bash +gh valet dry-run jenkins --source-url http://localhost:8080/job/test_pipeline -o .tmp/jenkins/dry-run --custom-transformers transformers.rb +``` + +When you open the file you should see the following changes in the GitHub Actions Workflow, note how the sleep timer step is no longer commented out! + +```diff +- # # This item has no matching transformer +- # - sleep: +- # - key: time +- # value: +- # isLiteral: true +- # value: 80 ++ - name: Sleep for 30 seconds ++ run: sleep 30s ++ shell: bash +``` + +## Custom transformers for a known step + +In our current scenario, the third-party GitHub action `EnricoMi/publish-unit-test-result-action@v1.7`, that Valet chose to transform for the `junit` step does not meet our needs because our CTO has dictated that our pipelines take no dependencies on third-party actions. We are able to customize the action that we would like Valet to use instead. + +After some research we find that the following scripts will execute our J-unit tests without needing to depend on `EnricoMi/publish-unit-test-result-action@v1.7`. + +```yaml +- name: Set up JDK 14 + uses: actions/setup-java@v1 + with: + java-version: 14 +- name: Cache Maven packages + uses: actions/cache@v2 + with: + path: ~/.m2 + key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }} + restore-keys: ${{ runner.os }}-m2 +- name: Run tests with Maven + run: mvn -B test --file pom.xml +``` + +We will build this custom transformation similar to how we built the previous custom transformer. This time, we need to add some additional logic. We would like to automate assigning each of the pipeline's file names to the run script. + +The challenge is, that we are unsure what `item` represents (what the incoming JSON object looks like from Jenkins). In order to troubleshoot this, you could use some basic ruby to print `item` to the terminal. You can achieve this by adding the following line in the transform method: `puts "This is the item: #{item}"`. + +You are able to add multiple custom transformers to the same file, so you can add this one right below the previous custom transformer. + +```ruby +transform "junit" do |item| + puts "This is the item: #{item}" +end +``` + +Let’s run the `dry-run` command to see what information is outputted in the terminal. + +```bash +gh valet dry-run jenkins --source-url http://localhost:8080/job/test_pipeline -o .tmp/jenkins/dry-run --custom-transformers transformers.rb +``` + +You should see something like the following outputted into the terminal: + +Screen Shot 2022-08-17 at 10 25 53 AM + +Now that we know the structure of the incoming JSON blob for `item` we can access the file path programmatically. + +```ruby +transform "junit" do |item| + test_results = item["arguments"].find{ |a| a["key"] == "testResults" } + file_path = test_results.dig("value", "value") + + [ + { + "name": "Set up JDK 14", + "uses": "actions/setup-java@v1", + "with": { + "java-version": 14 + } + }, + { + "name": "Cache Maven packages", + "uses": "actions/cache@v2", + "with": { + "path": "~/.m2", + "key": "${{ runner.os }}-m2-${{ hashFiles('**/#{file_path}') }}", + "restore-keys": "${{ runner.os }}-m2" + } + }, + { + "name": "Run tests with Maven", + "run": "mvn -B test --file #{file_path}" + } + ] +end +``` + +Your file should include both custom transformers. Ensure it matches the file below: + +__Click to Expand__ +
+ Custom Transformer file + +```ruby + transform "sleep" do |item| + { + "name": "Sleep for 30 seconds", + "run": "sleep 30s", + "shell": "bash" + } + end + + transform "junit" do |item| + test_results = item["arguments"].find{ |a| a["key"] == "testResults" } + file_path = test_results.dig("value", "value") + + [ + { + "name": "Set up JDK 14", + "uses": "actions/setup-java@v1", + "with": { + "java-version": 14 + } + }, + { + "name": "Cache Maven packages", + "uses": "actions/cache@v2", + "with": { + "path": "~/.m2", + "key": "${{ runner.os }}-m2-${{ hashFiles('**/#{file_path}') }}", + "restore-keys": "${{ runner.os }}-m2" + } + }, + { + "name": "Run tests with Maven", + "run": "mvn -B test --file #{file_path}" + } + ] + end +``` + +
+ +Let’s run the `dry-run` command again to see if our custom transformer worked. + +```bash +gh valet dry-run jenkins --source-url http://localhost:8080/job/test_pipeline -o .tmp/jenkins/dry-run --custom-transformers transformers.rb +``` + +When you open the file you should see the following workflow that has replaced the `EnricoMi/publish-unit-test-result-action@v1.7` action with the steps we have customized above. + +```diff +- - name: Publish test results +- uses: EnricoMi/publish-unit-test-result-action@v1.7 +- if: always() +- with: +- files: "**/target/*.xml" ++ - name: Set up JDK 14 ++ uses: actions/setup-java@v1 ++ with: ++ java-version: 14 ++ - name: Cache Maven packages ++ uses: actions/cache@v2 ++ with: ++ path: "~/.m2" ++ key: "${{ runner.os }}-m2-${{ hashFiles('**/**/target/*.xml') }}" ++ restore-keys: "${{ runner.os }}-m2" ++ - name: Run tests with Maven ++ run: mvn -B test --file **/target/*.xml +``` + +## Custom transformers for environment variables + +But wait! There's more we need to customize to make these pipelines fit our needs. Several of our pipelines will need to have the value of our `DB_ENGINE` environment variable changed from `sqlite` to `mongodb`. + +Valet allows you to replace values of `variables` by using the `env` method. Let’s replace the value for `DB_ENGINE` by using the below line. The first value of the `env` method is the target variable name and the second is the new value to be used. + + ```ruby + env "DB_ENGINE", "mongodb" + ``` + +You can keep adding these transformer values to your `transformer.rb` file. Your transformer file should look like the one below: + +__Click to Expand__ +
+ Custom Transformer file + +```ruby + env "DB_ENGINE", "mongodb" + + transform "sleep" do |item| + { + "name": "Sleep for 30 seconds", + "run": "sleep 30s", + "shell": "bash" + } + end + + transform "junit" do |item| + test_results = item["arguments"].find{ |a| a["key"] == "testResults" } + file_path = test_results.dig("value", "value") + + [ + { + "name": "Set up JDK 14", + "uses": "actions/setup-java@v1", + "with": { + "java-version": 14 + } + }, + { + "name": "Cache Maven packages", + "uses": "actions/cache@v2", + "with": { + "path": "~/.m2", + "key": "${{ runner.os }}-m2-${{ hashFiles('**/#{file_path}') }}", + "restore-keys": "${{ runner.os }}-m2" + } + }, + { + "name": "Run tests with Maven", + "run": "mvn -B test --file #{file_path}" + } + ] + end +``` + +
+ +Let’s run the `dry-run` command again to see if our custom transformer worked. + +```bash +gh valet dry-run jenkins --source-url http://localhost:8080/job/test_pipeline -o .tmp/jenkins/dry-run --custom-transformers transformers.rb +``` + +When you open the outputed file you should see that the value for `DB_ENGINE` has been changed from `sqlite` to `mongodb`. + +```diff +env: + DISABLE_AUTH: 'true' +- DB_ENGINE: sqlite ++ DB_ENGINE: mongodb +``` + +## Custom transformers for runners + +Lastly, several of our pipelines will need to have the runner label updated from `TeamARunner` to `ubuntu-latest`. + +Valet offers the ability to provide customized mapping between build agents in the source CI instance and their equivalent GitHub Actions runner labels. The syntax for providing an agent label mapping is similar to a environment variable transformer. + +A `runner` method is used with the first parameter being the Jenkins agent label and the second parameter being the GitHub Actions runner label(s) to map to. As an example, the following could be used: + + ```ruby + runner "TeamARunner", "ubuntu-latest" + ``` + +You can keep adding these transformer vales to your `transformer.rb` file. Your transformer file should look like the one below: + +__Click to Expand__ +
+ Custom Transformer file + +```ruby + runner "TeamARunner", "ubuntu-latest" + + env "DB_ENGINE", "mongodb" + + transform "sleep" do |item| + { + "name": "Sleep for 30 seconds", + "run": "sleep 30s", + "shell": "bash" + } + end + + transform "junit" do |item| + test_results = item["arguments"].find{ |a| a["key"] == "testResults" } + file_path = test_results.dig("value", "value") + + [ + { + "name": "Set up JDK 14", + "uses": "actions/setup-java@v1", + "with": { + "java-version": 14 + } + }, + { + "name": "Cache Maven packages", + "uses": "actions/cache@v2", + "with": { + "path": "~/.m2", + "key": "${{ runner.os }}-m2-${{ hashFiles('**/#{file_path}') }}", + "restore-keys": "${{ runner.os }}-m2" + } + }, + { + "name": "Run tests with Maven", + "run": "mvn -B test --file #{file_path}" + } + ] + end +``` + +
+ +Let’s run the `dry-run` command again to see if our custom transformer worked. + +```bash +gh valet dry-run jenkins --source-url http://localhost:8080/job/test_pipeline -o .tmp/jenkins/dry-run --custom-transformers transformers.rb +``` + +When you open the file you should see that the value for `TeamARunner` has been changed to `ubuntu-latest`. + +```diff +runs-on: +- - self-hosted +- - TeamARunner ++ - ubuntu-latest +``` + +Thats it! Congratulations you have customized transforming: + +- unsupported steps +- steps thata are supproted but don't meet your requirements +- enviroment variables +- runners + +## Next Lab + +[Migrating a Jenkins Pipeline](../jenkins/valet-migrate-lab.md) From 42cee0064c6d2c20a3a8f6a81a5b2a81ef2b1290 Mon Sep 17 00:00:00 2001 From: Begona Guereca Date: Wed, 17 Aug 2022 15:23:32 -0700 Subject: [PATCH 02/28] typo --- jenkins/valet-custom-transformers-lab.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jenkins/valet-custom-transformers-lab.md b/jenkins/valet-custom-transformers-lab.md index 0f8f83e..734a714 100644 --- a/jenkins/valet-custom-transformers-lab.md +++ b/jenkins/valet-custom-transformers-lab.md @@ -360,7 +360,7 @@ env: Lastly, several of our pipelines will need to have the runner label updated from `TeamARunner` to `ubuntu-latest`. -Valet offers the ability to provide customized mapping between build agents in the source CI instance and their equivalent GitHub Actions runner labels. The syntax for providing an agent label mapping is similar to a environment variable transformer. +Valet offers the ability to provide customized mapping between build agents in the source CI instance and their equivalent GitHub Actions runner labels. The syntax for providing an agent label mapping is similar to an environment variable transformer. A `runner` method is used with the first parameter being the Jenkins agent label and the second parameter being the GitHub Actions runner label(s) to map to. As an example, the following could be used: From e7000a25124a10006b1167e2fd046149ef7ea10a Mon Sep 17 00:00:00 2001 From: Begona Guereca Date: Thu, 18 Aug 2022 14:28:55 -0700 Subject: [PATCH 03/28] Update jenkins/valet-custom-transformers-lab.md Co-authored-by: j-dunham --- jenkins/valet-custom-transformers-lab.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jenkins/valet-custom-transformers-lab.md b/jenkins/valet-custom-transformers-lab.md index 734a714..c09f50d 100644 --- a/jenkins/valet-custom-transformers-lab.md +++ b/jenkins/valet-custom-transformers-lab.md @@ -11,7 +11,7 @@ These customizations will be present in many of our company's pipelines and an a - [Prerequisites](#prerequisites) - [Perform a dry-run](#perform-a-dry-run) -- [Custom transformers for an unknown step](#custom-transformers-for-unknown-step) +- [Custom transformers for an unknown step](#custom-transformers-for-an-unknown-step) - [Custom transformers for an known step](#custom-transformers-for-known-step) - [Custom transformers for environment variables](#custom-transformers-for-environment-varibales) - [Custom transformers for runners](#custom-transformers-for-runners) From 7c7b1746ff555022c193ee9fbdac8d281ed2c27e Mon Sep 17 00:00:00 2001 From: Begona Guereca Date: Mon, 22 Aug 2022 09:09:01 -0700 Subject: [PATCH 04/28] Update jenkins/valet-custom-transformers-lab.md Co-authored-by: j-dunham --- jenkins/valet-custom-transformers-lab.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jenkins/valet-custom-transformers-lab.md b/jenkins/valet-custom-transformers-lab.md index c09f50d..41dcc0f 100644 --- a/jenkins/valet-custom-transformers-lab.md +++ b/jenkins/valet-custom-transformers-lab.md @@ -436,7 +436,7 @@ runs-on: Thats it! Congratulations you have customized transforming: - unsupported steps -- steps thata are supproted but don't meet your requirements +- steps that are supported but don't meet your requirements - enviroment variables - runners From 7de4ea245d4395e689fbc2f470be272190b1e376 Mon Sep 17 00:00:00 2001 From: Begona Guereca Date: Mon, 22 Aug 2022 10:10:14 -0700 Subject: [PATCH 05/28] Update jenkins/valet-custom-transformers-lab.md Co-authored-by: j-dunham --- jenkins/valet-custom-transformers-lab.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jenkins/valet-custom-transformers-lab.md b/jenkins/valet-custom-transformers-lab.md index 41dcc0f..0c01d0b 100644 --- a/jenkins/valet-custom-transformers-lab.md +++ b/jenkins/valet-custom-transformers-lab.md @@ -368,7 +368,7 @@ A `runner` method is used with the first parameter being the Jenkins agent label runner "TeamARunner", "ubuntu-latest" ``` -You can keep adding these transformer vales to your `transformer.rb` file. Your transformer file should look like the one below: +You can keep adding these transformer methods to your `transformer.rb` file. Your transformer file should look like the one below: __Click to Expand__
From 2cc3f935ccfa28e5d81227c744a23016bfef5bb2 Mon Sep 17 00:00:00 2001 From: Begona Guereca Date: Mon, 22 Aug 2022 10:10:31 -0700 Subject: [PATCH 06/28] Update jenkins/valet-custom-transformers-lab.md Co-authored-by: j-dunham --- jenkins/valet-custom-transformers-lab.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jenkins/valet-custom-transformers-lab.md b/jenkins/valet-custom-transformers-lab.md index 0c01d0b..ed05b09 100644 --- a/jenkins/valet-custom-transformers-lab.md +++ b/jenkins/valet-custom-transformers-lab.md @@ -362,7 +362,7 @@ Lastly, several of our pipelines will need to have the runner label updated from Valet offers the ability to provide customized mapping between build agents in the source CI instance and their equivalent GitHub Actions runner labels. The syntax for providing an agent label mapping is similar to an environment variable transformer. -A `runner` method is used with the first parameter being the Jenkins agent label and the second parameter being the GitHub Actions runner label(s) to map to. As an example, the following could be used: +The `runner` methods first parameter is the Jenkins agent label and the second parameter is the GitHub Actions runner label(s) to map too. As an example, the following could be used: ```ruby runner "TeamARunner", "ubuntu-latest" From ee1633d33c826aca7b8ad8472b069c1f387bb317 Mon Sep 17 00:00:00 2001 From: Begona Guereca Date: Mon, 22 Aug 2022 10:10:44 -0700 Subject: [PATCH 07/28] Update jenkins/valet-custom-transformers-lab.md Co-authored-by: j-dunham --- jenkins/valet-custom-transformers-lab.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jenkins/valet-custom-transformers-lab.md b/jenkins/valet-custom-transformers-lab.md index ed05b09..09bb874 100644 --- a/jenkins/valet-custom-transformers-lab.md +++ b/jenkins/valet-custom-transformers-lab.md @@ -360,7 +360,7 @@ env: Lastly, several of our pipelines will need to have the runner label updated from `TeamARunner` to `ubuntu-latest`. -Valet offers the ability to provide customized mapping between build agents in the source CI instance and their equivalent GitHub Actions runner labels. The syntax for providing an agent label mapping is similar to an environment variable transformer. +Valet offers the ability to provide customized mapping between build agents in the source CI instance and their equivalent GitHub Actions runner labels by using the `runner` method. The syntax for this is similar to the `env` method. The `runner` methods first parameter is the Jenkins agent label and the second parameter is the GitHub Actions runner label(s) to map too. As an example, the following could be used: From e61d7d6d1d138360a70e4b6fa54dfad9c69ec260 Mon Sep 17 00:00:00 2001 From: Begona Guereca Date: Mon, 22 Aug 2022 10:10:51 -0700 Subject: [PATCH 08/28] Update jenkins/valet-custom-transformers-lab.md Co-authored-by: j-dunham --- jenkins/valet-custom-transformers-lab.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jenkins/valet-custom-transformers-lab.md b/jenkins/valet-custom-transformers-lab.md index 09bb874..9a302b6 100644 --- a/jenkins/valet-custom-transformers-lab.md +++ b/jenkins/valet-custom-transformers-lab.md @@ -285,7 +285,7 @@ When you open the file you should see the following workflow that has replaced t ## Custom transformers for environment variables -But wait! There's more we need to customize to make these pipelines fit our needs. Several of our pipelines will need to have the value of our `DB_ENGINE` environment variable changed from `sqlite` to `mongodb`. +But wait! There's more we need to customize to make these pipelines fit our needs. Several of our pipelines will need to have the value of the `DB_ENGINE` environment variable changed from `sqlite` to `mongodb`. Valet allows you to replace values of `variables` by using the `env` method. Let’s replace the value for `DB_ENGINE` by using the below line. The first value of the `env` method is the target variable name and the second is the new value to be used. From 62d5394565a40b4209955dd687bf2167e82258f4 Mon Sep 17 00:00:00 2001 From: Begona Guereca Date: Mon, 22 Aug 2022 10:11:00 -0700 Subject: [PATCH 09/28] Update jenkins/valet-custom-transformers-lab.md Co-authored-by: j-dunham --- jenkins/valet-custom-transformers-lab.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jenkins/valet-custom-transformers-lab.md b/jenkins/valet-custom-transformers-lab.md index 9a302b6..4e4f2ad 100644 --- a/jenkins/valet-custom-transformers-lab.md +++ b/jenkins/valet-custom-transformers-lab.md @@ -261,7 +261,7 @@ Let’s run the `dry-run` command again to see if our custom transformer worked. gh valet dry-run jenkins --source-url http://localhost:8080/job/test_pipeline -o .tmp/jenkins/dry-run --custom-transformers transformers.rb ``` -When you open the file you should see the following workflow that has replaced the `EnricoMi/publish-unit-test-result-action@v1.7` action with the steps we have customized above. +When you open the file you should see the`EnricoMi/publish-unit-test-result-action@v1.7` action has been replaced with the customized steps. ```diff - - name: Publish test results From 5eec128d0a50b7029f0379fbcd2fb1c6b443767c Mon Sep 17 00:00:00 2001 From: Begona Guereca Date: Mon, 22 Aug 2022 10:12:10 -0700 Subject: [PATCH 10/28] Update jenkins/valet-custom-transformers-lab.md Co-authored-by: j-dunham --- jenkins/valet-custom-transformers-lab.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jenkins/valet-custom-transformers-lab.md b/jenkins/valet-custom-transformers-lab.md index 4e4f2ad..6090cfd 100644 --- a/jenkins/valet-custom-transformers-lab.md +++ b/jenkins/valet-custom-transformers-lab.md @@ -136,7 +136,7 @@ When you open the file you should see the following changes in the GitHub Action ## Custom transformers for a known step -In our current scenario, the third-party GitHub action `EnricoMi/publish-unit-test-result-action@v1.7`, that Valet chose to transform for the `junit` step does not meet our needs because our CTO has dictated that our pipelines take no dependencies on third-party actions. We are able to customize the action that we would like Valet to use instead. +Next lets address the third-party GitHub action `EnricoMi/publish-unit-test-result-action@v1.7`, that Valet chose for the `junit` step. This action does not meet our needs because our CTO has dictated that our pipelines take no dependencies on third-party actions. We can customize the action that we would like Valet to use instead. After some research we find that the following scripts will execute our J-unit tests without needing to depend on `EnricoMi/publish-unit-test-result-action@v1.7`. From f01c2787fac9a35f16286624ef279bd76aae4177 Mon Sep 17 00:00:00 2001 From: Begona Guereca Date: Mon, 22 Aug 2022 10:12:20 -0700 Subject: [PATCH 11/28] Update jenkins/valet-custom-transformers-lab.md Co-authored-by: j-dunham --- jenkins/valet-custom-transformers-lab.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jenkins/valet-custom-transformers-lab.md b/jenkins/valet-custom-transformers-lab.md index 6090cfd..9e22e1a 100644 --- a/jenkins/valet-custom-transformers-lab.md +++ b/jenkins/valet-custom-transformers-lab.md @@ -114,7 +114,7 @@ The ruby hash can be thought of as the JSON representation of the YAML we want. end ``` -Let’s run the `dry-run` command again to see if our custom transformer worked. +Let’s run the `dry-run` command again with `--custom-transformer transformers.rb` to see if our custom transformer worked. ```bash gh valet dry-run jenkins --source-url http://localhost:8080/job/test_pipeline -o .tmp/jenkins/dry-run --custom-transformers transformers.rb From 9ee41b280a93ec9bcd47f820e3fb551422737f4a Mon Sep 17 00:00:00 2001 From: Begona Guereca Date: Mon, 22 Aug 2022 10:13:20 -0700 Subject: [PATCH 12/28] Update jenkins/valet-custom-transformers-lab.md Co-authored-by: j-dunham --- jenkins/valet-custom-transformers-lab.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jenkins/valet-custom-transformers-lab.md b/jenkins/valet-custom-transformers-lab.md index 9e22e1a..eafff1f 100644 --- a/jenkins/valet-custom-transformers-lab.md +++ b/jenkins/valet-custom-transformers-lab.md @@ -100,7 +100,7 @@ Now that we know the final yaml needed for the transformer, we can start to writ - Create a new file where you will put the custom transformers logic. It can have any file name, but it is recommended that you use an `.rb` extension so the codespaces editor knows it is a ruby file and can provide syntax highlighting. For this example we will call it `transformers.rb`. -In the custom transformers file we will call the `transform` method. This is a special method that Valet exposes, that takes the identifier we determined earlier and returns a ruby hash of the final YAML for the pipeline. +In the custom transformers file we will add a `transform` method. This is a special method that Valet exposes, that takes the identifier we determined earlier and returns a ruby hash of the final YAML for the pipeline. The ruby hash can be thought of as the JSON representation of the YAML we want. Valet will call that method when it encounters the identifier and pass in an `item`. The `item` is the values defined for that step in Jenkins. In this case the item is the path of the sleep command. From c9eba8bb5b23a91fef27863751656e15789d85c0 Mon Sep 17 00:00:00 2001 From: Begona Guereca Date: Mon, 22 Aug 2022 10:13:36 -0700 Subject: [PATCH 13/28] Update jenkins/valet-custom-transformers-lab.md Co-authored-by: j-dunham --- jenkins/valet-custom-transformers-lab.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jenkins/valet-custom-transformers-lab.md b/jenkins/valet-custom-transformers-lab.md index eafff1f..0b9db2e 100644 --- a/jenkins/valet-custom-transformers-lab.md +++ b/jenkins/valet-custom-transformers-lab.md @@ -13,7 +13,7 @@ These customizations will be present in many of our company's pipelines and an a - [Perform a dry-run](#perform-a-dry-run) - [Custom transformers for an unknown step](#custom-transformers-for-an-unknown-step) - [Custom transformers for an known step](#custom-transformers-for-known-step) -- [Custom transformers for environment variables](#custom-transformers-for-environment-varibales) +- [Custom transformers for environment variables](#custom-transformers-for-environment-variables) - [Custom transformers for runners](#custom-transformers-for-runners) - [Next Lab](#next-lab) From f364031d04378724b99026ede511e9256c7e4468 Mon Sep 17 00:00:00 2001 From: Begona Guereca Date: Mon, 22 Aug 2022 10:13:41 -0700 Subject: [PATCH 14/28] Update jenkins/valet-custom-transformers-lab.md Co-authored-by: j-dunham --- jenkins/valet-custom-transformers-lab.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jenkins/valet-custom-transformers-lab.md b/jenkins/valet-custom-transformers-lab.md index 0b9db2e..a061d7f 100644 --- a/jenkins/valet-custom-transformers-lab.md +++ b/jenkins/valet-custom-transformers-lab.md @@ -12,7 +12,7 @@ These customizations will be present in many of our company's pipelines and an a - [Prerequisites](#prerequisites) - [Perform a dry-run](#perform-a-dry-run) - [Custom transformers for an unknown step](#custom-transformers-for-an-unknown-step) -- [Custom transformers for an known step](#custom-transformers-for-known-step) +- [Custom transformers for an known step](#custom-transformers-for-a-known-step) - [Custom transformers for environment variables](#custom-transformers-for-environment-variables) - [Custom transformers for runners](#custom-transformers-for-runners) - [Next Lab](#next-lab) From ec53736cd134a3315a1df9e7513e9d406175c5f5 Mon Sep 17 00:00:00 2001 From: Begona Guereca Date: Mon, 22 Aug 2022 10:13:54 -0700 Subject: [PATCH 15/28] Update jenkins/valet-custom-transformers-lab.md Co-authored-by: j-dunham --- jenkins/valet-custom-transformers-lab.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jenkins/valet-custom-transformers-lab.md b/jenkins/valet-custom-transformers-lab.md index a061d7f..2367c21 100644 --- a/jenkins/valet-custom-transformers-lab.md +++ b/jenkins/valet-custom-transformers-lab.md @@ -1,6 +1,6 @@ # Using Custom Transformers in a `dry-run` -In this lab we want to do a `dry-run` of the `test_pipeline` pipeline, however, after a closer inspection, we have discovered that we will need to be customize the transformation of: +In this lab we want to do a `dry-run` of the `test_pipeline` pipeline, however, after a closer inspection, we discovered that we will need to customize how Valet transforms: 1. Steps that are unsupported by Valet, buts are essential to our devops process. 2. Steps in which the GitHub action chosen by Valet does not meet our current needs. From da29203c885786f298712a3d276f1e4c848ed0f2 Mon Sep 17 00:00:00 2001 From: Begona Guereca Date: Mon, 22 Aug 2022 10:29:56 -0700 Subject: [PATCH 16/28] Update jenkins/valet-custom-transformers-lab.md Co-authored-by: j-dunham --- jenkins/valet-custom-transformers-lab.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jenkins/valet-custom-transformers-lab.md b/jenkins/valet-custom-transformers-lab.md index 2367c21..ecf9da4 100644 --- a/jenkins/valet-custom-transformers-lab.md +++ b/jenkins/valet-custom-transformers-lab.md @@ -102,7 +102,7 @@ Now that we know the final yaml needed for the transformer, we can start to writ In the custom transformers file we will add a `transform` method. This is a special method that Valet exposes, that takes the identifier we determined earlier and returns a ruby hash of the final YAML for the pipeline. -The ruby hash can be thought of as the JSON representation of the YAML we want. Valet will call that method when it encounters the identifier and pass in an `item`. The `item` is the values defined for that step in Jenkins. In this case the item is the path of the sleep command. +The ruby hash can be thought of as the JSON representation of the YAML we want. Valet will call that method when it encounters the identifier and pass in an `item`. The `item` is the key of that key/value pair defined for that step in Jenkins. In this case the item is the settings of the sleep command. ```ruby transform "sleep" do |item| From 379b2a318722a364bb55490caab1903fce7a7cc7 Mon Sep 17 00:00:00 2001 From: Begona Guereca Date: Mon, 22 Aug 2022 12:09:55 -0700 Subject: [PATCH 17/28] Update jenkins/valet-custom-transformers-lab.md --- jenkins/valet-custom-transformers-lab.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jenkins/valet-custom-transformers-lab.md b/jenkins/valet-custom-transformers-lab.md index ecf9da4..b467832 100644 --- a/jenkins/valet-custom-transformers-lab.md +++ b/jenkins/valet-custom-transformers-lab.md @@ -82,7 +82,7 @@ jobs:
-Go back to the previous lab [Dry-run Jenkins Pipeline](../jenkins/valet-migrate-lab.md) if you need a review of the details of the dry-run. +Go back to the previous lab [Dry-run Jenkins Pipeline](../jenkins/valet-dry-run-lab.md) if you need a review of the details of the dry-run. ## Custom transformers for an unknown step From b90363e8e4c4ba8123a517890d898a3d1d6c4b62 Mon Sep 17 00:00:00 2001 From: Begona Guereca Date: Mon, 22 Aug 2022 12:10:54 -0700 Subject: [PATCH 18/28] Update jenkins/valet-custom-transformers-lab.md Co-authored-by: Ethan Dennis --- jenkins/valet-custom-transformers-lab.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jenkins/valet-custom-transformers-lab.md b/jenkins/valet-custom-transformers-lab.md index b467832..1a1e5a6 100644 --- a/jenkins/valet-custom-transformers-lab.md +++ b/jenkins/valet-custom-transformers-lab.md @@ -5,7 +5,7 @@ In this lab we want to do a `dry-run` of the `test_pipeline` pipeline, however, 1. Steps that are unsupported by Valet, buts are essential to our devops process. 2. Steps in which the GitHub action chosen by Valet does not meet our current needs. 3. All pipelines that have the environment variable `DB_ENGINE` must be changed to a different value: `mongodb`. -4. The self-hosted runners before were called `TeamARunner` and with the GitHub Migration they will be called `ubuntu-latest`. +4. The self-hosted runners before used the `TeamARunner` label in Jenkins but will run on the `ubuntu-latest` runner in Actions. These customizations will be present in many of our company's pipelines and an automated way to apply these changes would be ideal. In this lab, we will use the `--custom-transformers` flag to change the behavior of Valet using its DSL built on top of the Ruby language. From b3a500259957877e5ffdc440c79caeae0bc93493 Mon Sep 17 00:00:00 2001 From: Begona Guereca Date: Mon, 22 Aug 2022 12:12:22 -0700 Subject: [PATCH 19/28] Update jenkins/valet-custom-transformers-lab.md Co-authored-by: Ethan Dennis --- jenkins/valet-custom-transformers-lab.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/jenkins/valet-custom-transformers-lab.md b/jenkins/valet-custom-transformers-lab.md index 1a1e5a6..afb7c35 100644 --- a/jenkins/valet-custom-transformers-lab.md +++ b/jenkins/valet-custom-transformers-lab.md @@ -106,9 +106,11 @@ The ruby hash can be thought of as the JSON representation of the YAML we want. ```ruby transform "sleep" do |item| + wait_time = item[0]["value"]["value"] + { - "name": "Sleep for 30 seconds", - "run": "sleep 30s", + "name": "Sleep for #{wait_time} seconds", + "run": "sleep #{wait_time}s", "shell": "bash" } end From db6470bbb4b1deada3c5708dd1715ce80501be37 Mon Sep 17 00:00:00 2001 From: Begona Guereca Date: Mon, 22 Aug 2022 12:16:03 -0700 Subject: [PATCH 20/28] Update jenkins/valet-custom-transformers-lab.md --- jenkins/valet-custom-transformers-lab.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jenkins/valet-custom-transformers-lab.md b/jenkins/valet-custom-transformers-lab.md index afb7c35..1c66ddb 100644 --- a/jenkins/valet-custom-transformers-lab.md +++ b/jenkins/valet-custom-transformers-lab.md @@ -2,7 +2,7 @@ In this lab we want to do a `dry-run` of the `test_pipeline` pipeline, however, after a closer inspection, we discovered that we will need to customize how Valet transforms: -1. Steps that are unsupported by Valet, buts are essential to our devops process. +1. Steps that are unsupported by Valet, but are essential to our devops process. 2. Steps in which the GitHub action chosen by Valet does not meet our current needs. 3. All pipelines that have the environment variable `DB_ENGINE` must be changed to a different value: `mongodb`. 4. The self-hosted runners before used the `TeamARunner` label in Jenkins but will run on the `ubuntu-latest` runner in Actions. From c025b21e11249fef0af32712ebf2f3dd26aec8d7 Mon Sep 17 00:00:00 2001 From: Begona Guereca Date: Mon, 22 Aug 2022 14:37:24 -0700 Subject: [PATCH 21/28] Update jenkins/valet-custom-transformers-lab.md --- jenkins/valet-custom-transformers-lab.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jenkins/valet-custom-transformers-lab.md b/jenkins/valet-custom-transformers-lab.md index 1c66ddb..3720c96 100644 --- a/jenkins/valet-custom-transformers-lab.md +++ b/jenkins/valet-custom-transformers-lab.md @@ -130,7 +130,7 @@ When you open the file you should see the following changes in the GitHub Action - # - key: time - # value: - # isLiteral: true -- # value: 80 +- # value: 30 + - name: Sleep for 30 seconds + run: sleep 30s + shell: bash From b548deb8c8730b27627be159808fd8910827bb40 Mon Sep 17 00:00:00 2001 From: Begona Guereca Date: Mon, 22 Aug 2022 14:37:55 -0700 Subject: [PATCH 22/28] Update jenkins/valet-custom-transformers-lab.md --- jenkins/valet-custom-transformers-lab.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jenkins/valet-custom-transformers-lab.md b/jenkins/valet-custom-transformers-lab.md index 3720c96..537214f 100644 --- a/jenkins/valet-custom-transformers-lab.md +++ b/jenkins/valet-custom-transformers-lab.md @@ -138,7 +138,7 @@ When you open the file you should see the following changes in the GitHub Action ## Custom transformers for a known step -Next lets address the third-party GitHub action `EnricoMi/publish-unit-test-result-action@v1.7`, that Valet chose for the `junit` step. This action does not meet our needs because our CTO has dictated that our pipelines take no dependencies on third-party actions. We can customize the action that we would like Valet to use instead. +Next lets address the third-party GitHub action `EnricoMi/publish-unit-test-result-action@v1.7` that Valet chose for the `junit` step. This action does not meet our needs because our CTO has dictated that our pipelines take no dependencies on third-party actions. We can customize the action that we would like Valet to use instead. After some research we find that the following scripts will execute our J-unit tests without needing to depend on `EnricoMi/publish-unit-test-result-action@v1.7`. From a3f063feb56419f7a84370e8c7bb166da01d63e5 Mon Sep 17 00:00:00 2001 From: Begona Guereca Date: Mon, 22 Aug 2022 16:05:55 -0700 Subject: [PATCH 23/28] Update jenkins/valet-custom-transformers-lab.md --- jenkins/valet-custom-transformers-lab.md | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/jenkins/valet-custom-transformers-lab.md b/jenkins/valet-custom-transformers-lab.md index 537214f..ef2a1dd 100644 --- a/jenkins/valet-custom-transformers-lab.md +++ b/jenkins/valet-custom-transformers-lab.md @@ -143,18 +143,10 @@ Next lets address the third-party GitHub action `EnricoMi/publish-unit-test-resu After some research we find that the following scripts will execute our J-unit tests without needing to depend on `EnricoMi/publish-unit-test-result-action@v1.7`. ```yaml -- name: Set up JDK 14 - uses: actions/setup-java@v1 +- uses: actions/upload-artifact@v3 with: - java-version: 14 -- name: Cache Maven packages - uses: actions/cache@v2 - with: - path: ~/.m2 - key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }} - restore-keys: ${{ runner.os }}-m2 -- name: Run tests with Maven - run: mvn -B test --file pom.xml + name: my-artifact + path: path/to/artifact/world.txt ``` We will build this custom transformation similar to how we built the previous custom transformer. This time, we need to add some additional logic. We would like to automate assigning each of the pipeline's file names to the run script. From 5024c7f0b70b1e8a65230eb37840d95c8c66d39f Mon Sep 17 00:00:00 2001 From: Begona Guereca Date: Mon, 22 Aug 2022 16:20:18 -0700 Subject: [PATCH 24/28] udpates --- jenkins/valet-custom-transformers-lab.md | 26 +++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/jenkins/valet-custom-transformers-lab.md b/jenkins/valet-custom-transformers-lab.md index ef2a1dd..0600e45 100644 --- a/jenkins/valet-custom-transformers-lab.md +++ b/jenkins/valet-custom-transformers-lab.md @@ -48,7 +48,7 @@ env: DISABLE_AUTH: 'true' DB_ENGINE: sqlite jobs: - build: + check_env_variables: runs-on: - self-hosted - TeamARunner @@ -65,6 +65,22 @@ jobs: # value: 80 - name: echo message run: echo "DISABLE_AUTH is ${{ env.DISABLE_AUTH }}" + build: + runs-on: + - self-hosted + - TeamARunner + needs: check_env_variables + steps: + - name: checkout + uses: actions/checkout@v2 + - name: Set up JDK 1.11 + uses: actions/setup-java@v1 + with: + java-version: '1.11' + settings-path: "${{ github.workspace }}" + - name: sh + shell: bash + run: mvn clean package test: runs-on: - self-hosted @@ -106,7 +122,7 @@ The ruby hash can be thought of as the JSON representation of the YAML we want. ```ruby transform "sleep" do |item| - wait_time = item[0]["value"]["value"] + wait_time = item["arguments"][0]["value"]["value"] { "name": "Sleep for #{wait_time} seconds", @@ -130,9 +146,9 @@ When you open the file you should see the following changes in the GitHub Action - # - key: time - # value: - # isLiteral: true -- # value: 30 -+ - name: Sleep for 30 seconds -+ run: sleep 30s +- # value: 80 ++ - name: Sleep for 80 seconds ++ run: sleep 80s + shell: bash ``` From 1ac8ea116e2960db7b74f79a7bbde859ebb56695 Mon Sep 17 00:00:00 2001 From: Begona Guereca Date: Mon, 22 Aug 2022 16:39:24 -0700 Subject: [PATCH 25/28] Updated junit --- jenkins/valet-custom-transformers-lab.md | 142 +++++++---------------- 1 file changed, 44 insertions(+), 98 deletions(-) diff --git a/jenkins/valet-custom-transformers-lab.md b/jenkins/valet-custom-transformers-lab.md index 0600e45..803595e 100644 --- a/jenkins/valet-custom-transformers-lab.md +++ b/jenkins/valet-custom-transformers-lab.md @@ -107,8 +107,8 @@ We can see in the center of the transformed workflow that the `sleep` step was n After some research we have decided that a simple bash script will meet our needs: ```yaml - - name: Sleep for 30 seconds - run: sleep 30s + - name: Sleep for 80 seconds + run: sleep 80s shell: bash ``` @@ -161,7 +161,7 @@ After some research we find that the following scripts will execute our J-unit t ```yaml - uses: actions/upload-artifact@v3 with: - name: my-artifact + name: junit-artifact path: path/to/artifact/world.txt ``` @@ -194,28 +194,15 @@ transform "junit" do |item| test_results = item["arguments"].find{ |a| a["key"] == "testResults" } file_path = test_results.dig("value", "value") - [ - { - "name": "Set up JDK 14", - "uses": "actions/setup-java@v1", - "with": { - "java-version": 14 + [ + { + "uses": "actions/upload-artifact@v3", + "with": { + "name": "junit-artifact", + "path": file_path + } } - }, - { - "name": "Cache Maven packages", - "uses": "actions/cache@v2", - "with": { - "path": "~/.m2", - "key": "${{ runner.os }}-m2-${{ hashFiles('**/#{file_path}') }}", - "restore-keys": "${{ runner.os }}-m2" - } - }, - { - "name": "Run tests with Maven", - "run": "mvn -B test --file #{file_path}" - } - ] + ] end ``` @@ -227,11 +214,13 @@ __Click to Expand__ ```ruby transform "sleep" do |item| - { - "name": "Sleep for 30 seconds", - "run": "sleep 30s", - "shell": "bash" - } + wait_time = item["arguments"][0]["value"]["value"] + + { + "name": "Sleep for #{wait_time} seconds", + "run": "sleep #{wait_time}s", + "shell": "bash" + } end transform "junit" do |item| @@ -240,24 +229,11 @@ __Click to Expand__ [ { - "name": "Set up JDK 14", - "uses": "actions/setup-java@v1", + "uses": "actions/upload-artifact@v3", "with": { - "java-version": 14 + "name": "junit-artifact", + "path": file_path } - }, - { - "name": "Cache Maven packages", - "uses": "actions/cache@v2", - "with": { - "path": "~/.m2", - "key": "${{ runner.os }}-m2-${{ hashFiles('**/#{file_path}') }}", - "restore-keys": "${{ runner.os }}-m2" - } - }, - { - "name": "Run tests with Maven", - "run": "mvn -B test --file #{file_path}" } ] end @@ -279,18 +255,10 @@ When you open the file you should see the`EnricoMi/publish-unit-test-result-acti - if: always() - with: - files: "**/target/*.xml" -+ - name: Set up JDK 14 -+ uses: actions/setup-java@v1 ++ - uses: actions/upload-artifact@v3 + with: -+ java-version: 14 -+ - name: Cache Maven packages -+ uses: actions/cache@v2 -+ with: -+ path: "~/.m2" -+ key: "${{ runner.os }}-m2-${{ hashFiles('**/**/target/*.xml') }}" -+ restore-keys: "${{ runner.os }}-m2" -+ - name: Run tests with Maven -+ run: mvn -B test --file **/target/*.xml ++ name: junit-artifact ++ path: path/to/artifact/world.txt ``` ## Custom transformers for environment variables @@ -313,11 +281,13 @@ __Click to Expand__ env "DB_ENGINE", "mongodb" transform "sleep" do |item| - { - "name": "Sleep for 30 seconds", - "run": "sleep 30s", - "shell": "bash" - } + wait_time = item["arguments"][0]["value"]["value"] + + { + "name": "Sleep for #{wait_time} seconds", + "run": "sleep #{wait_time}s", + "shell": "bash" + } end transform "junit" do |item| @@ -326,24 +296,11 @@ __Click to Expand__ [ { - "name": "Set up JDK 14", - "uses": "actions/setup-java@v1", + "uses": "actions/upload-artifact@v3", "with": { - "java-version": 14 + "name": "my-artifact", + "path": file_path } - }, - { - "name": "Cache Maven packages", - "uses": "actions/cache@v2", - "with": { - "path": "~/.m2", - "key": "${{ runner.os }}-m2-${{ hashFiles('**/#{file_path}') }}", - "restore-keys": "${{ runner.os }}-m2" - } - }, - { - "name": "Run tests with Maven", - "run": "mvn -B test --file #{file_path}" } ] end @@ -390,11 +347,13 @@ __Click to Expand__ env "DB_ENGINE", "mongodb" transform "sleep" do |item| - { - "name": "Sleep for 30 seconds", - "run": "sleep 30s", - "shell": "bash" - } + wait_time = item["arguments"][0]["value"]["value"] + + { + "name": "Sleep for #{wait_time} seconds", + "run": "sleep #{wait_time}s", + "shell": "bash" + } end transform "junit" do |item| @@ -403,24 +362,11 @@ __Click to Expand__ [ { - "name": "Set up JDK 14", - "uses": "actions/setup-java@v1", + "uses": "actions/upload-artifact@v3", "with": { - "java-version": 14 + "name": "my-artifact", + "path": file_path } - }, - { - "name": "Cache Maven packages", - "uses": "actions/cache@v2", - "with": { - "path": "~/.m2", - "key": "${{ runner.os }}-m2-${{ hashFiles('**/#{file_path}') }}", - "restore-keys": "${{ runner.os }}-m2" - } - }, - { - "name": "Run tests with Maven", - "run": "mvn -B test --file #{file_path}" } ] end From 50e517781723aa54a6adde4718abf120b3f0136f Mon Sep 17 00:00:00 2001 From: Begona Guereca Date: Tue, 23 Aug 2022 09:18:19 -0700 Subject: [PATCH 26/28] Update jenkins/valet-custom-transformers-lab.md Co-authored-by: Ethan Dennis --- jenkins/valet-custom-transformers-lab.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jenkins/valet-custom-transformers-lab.md b/jenkins/valet-custom-transformers-lab.md index 803595e..22a690c 100644 --- a/jenkins/valet-custom-transformers-lab.md +++ b/jenkins/valet-custom-transformers-lab.md @@ -156,7 +156,7 @@ When you open the file you should see the following changes in the GitHub Action Next lets address the third-party GitHub action `EnricoMi/publish-unit-test-result-action@v1.7` that Valet chose for the `junit` step. This action does not meet our needs because our CTO has dictated that our pipelines take no dependencies on third-party actions. We can customize the action that we would like Valet to use instead. -After some research we find that the following scripts will execute our J-unit tests without needing to depend on `EnricoMi/publish-unit-test-result-action@v1.7`. +After some research we find that the following action will upload an artifact with the junit test results without depending on a third party action. ```yaml - uses: actions/upload-artifact@v3 From cfe95685f2b2c4630bae16169b70780064511eb6 Mon Sep 17 00:00:00 2001 From: Begona Guereca Date: Tue, 23 Aug 2022 09:23:41 -0700 Subject: [PATCH 27/28] Update jenkins/valet-custom-transformers-lab.md Co-authored-by: Ethan Dennis --- jenkins/valet-custom-transformers-lab.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jenkins/valet-custom-transformers-lab.md b/jenkins/valet-custom-transformers-lab.md index 22a690c..98dfe65 100644 --- a/jenkins/valet-custom-transformers-lab.md +++ b/jenkins/valet-custom-transformers-lab.md @@ -165,7 +165,7 @@ After some research we find that the following action will upload an artifact wi path: path/to/artifact/world.txt ``` -We will build this custom transformation similar to how we built the previous custom transformer. This time, we need to add some additional logic. We would like to automate assigning each of the pipeline's file names to the run script. +We will build this custom transformer similar to how we built the previous custom transformer. This time, we need to add some additional logic. We would like to automate assigning each of the pipeline's file names to the run script. The challenge is, that we are unsure what `item` represents (what the incoming JSON object looks like from Jenkins). In order to troubleshoot this, you could use some basic ruby to print `item` to the terminal. You can achieve this by adding the following line in the transform method: `puts "This is the item: #{item}"`. From 213c83162239366b501aec7a9137480144ff02bd Mon Sep 17 00:00:00 2001 From: Begona Guereca Date: Tue, 23 Aug 2022 09:25:43 -0700 Subject: [PATCH 28/28] Update jenkins/valet-custom-transformers-lab.md --- jenkins/valet-custom-transformers-lab.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jenkins/valet-custom-transformers-lab.md b/jenkins/valet-custom-transformers-lab.md index 98dfe65..15654d6 100644 --- a/jenkins/valet-custom-transformers-lab.md +++ b/jenkins/valet-custom-transformers-lab.md @@ -165,7 +165,7 @@ After some research we find that the following action will upload an artifact wi path: path/to/artifact/world.txt ``` -We will build this custom transformer similar to how we built the previous custom transformer. This time, we need to add some additional logic. We would like to automate assigning each of the pipeline's file names to the run script. +We will build this custom transformer similar to how we built the previous custom transformer. This time, we need to add some additional logic. We would like to programmatically assign the file path to junit's test results to our upload action. The challenge is, that we are unsure what `item` represents (what the incoming JSON object looks like from Jenkins). In order to troubleshoot this, you could use some basic ruby to print `item` to the terminal. You can achieve this by adding the following line in the transform method: `puts "This is the item: #{item}"`.