DEV Community

Cover image for Generate JMeter Test Report and save it as artifact with GitHUB Actions
Boga Sebastian Nicolae
Boga Sebastian Nicolae

Posted on

Generate JMeter Test Report and save it as artifact with GitHUB Actions

I extended the workflow from GitHUB Actions presented in previous article (execute-all-jmeter-files-with-github-actions) so now we can generate and save the JMeter Test Report with GitHUB Actions.

My Workflow

  1. checkout actions/checkout@v2
  2. create test_report
  3. displays the current folder (you can refer to this folder like this $GITHUB_WORKSPACE)
  4. install the JMeter version 5.4.1(here we also display the jmeter version and also the current folder location)
  5. install the plugins for JMeter(here we just install the Dummy Sampler, but you can add any other plugin needed by your jmeter script; you can see all the available plugins here: https://jmeter-plugins.org/files/packages)
  6. run each jmx file from the repo
  7. create a folder for each jmx file (for each JMeter Test Plan)
  8. save jmeter test report(HTML format) in the folder created at previous step
  9. upload JMeter Test Results for all jmx files as artifact

Submission Category:

Maintainer Must-Haves,
DIY Deployments

Yaml File or Link to Code

GitHub logo sebiboga / jmeter_one

JMeter scripts

jmeter_one

  • different JMeter scripts
  • GitHUB Actions used to define the workflow to run all jmeter scripts from repository [main branch]
  • GitHUB Actions used to define the workflow to run all jmeter scripts from repository and save Test Report as artifact [main branch]
  • GitHUB Actions used to define the workflow to run all jmeter scripts from repository, generate JTL file and then generates CSV file from JTL file, and then save JTL&CSV as artifact [main branch]





# This is a workflow to help you run all JMeter scripts with Actions, and save Test Results as artifact

name: jmeter_test_results

# Controls when the workflow will run
on:
  # Triggers the workflow on push or pull request events but only for the main branch
  push:
    branches: [ main ]


  # Allows you to run this workflow manually from the Actions tab
  workflow_dispatch:

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
  # This workflow contains a single job called "build"
  build:
    # The type of runner that the job will run on
    runs-on: ubuntu-latest

    # Steps represent a sequence of tasks that will be executed as part of the job
    steps:
      # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
      - uses: actions/checkout@v2
      - name: where are the files?
        run: |
           pwd
           ls
      - name: create test_report
        run: |
           mkdir $GITHUB_WORKSPACE/test_report

      # Runs a set of commands using the runners shell
      - name: install jmeter
        run: |
          java -version
          wget https://downloads.apache.org//jmeter/binaries/apache-jmeter-5.4.1.zip
          unzip apache-jmeter-5.4.1.zip
          cd apache-jmeter-5.4.1/bin
          ./jmeter -v
          pwd

      - name: install plugins
        run: |
          cd $GITHUB_WORKSPACE/apache-jmeter-5.4.1
          wget -q --no-check-certificate https://jmeter-plugins.org/files/packages/jpgc-dummy-0.4.zip  -P .
          unzip -o jpgc-dummy-0.4.zip  && rm jpgc-dummy-0.4.zip

      - name: run jmx scripts
        run: |
         cd $GITHUB_WORKSPACE
         for i in $( ls -A1 *.jmx); do
            cd $GITHUB_WORKSPACE/apache-jmeter-5.4.1/bin
            mkdir $GITHUB_WORKSPACE/test_report/${i%.jmx}
            ./jmeter -n -t $GITHUB_WORKSPACE/$i  -l $GITHUB_WORKSPACE/${i%.jmx}.jtl -e -o $GITHUB_WORKSPACE/test_report/${i%.jmx}
         done
      - name: Upload JMeter Test Results
        uses: actions/upload-artifact@v2.2.4
        with:
         name: test_results
         path: test_report
Enter fullscreen mode Exit fullscreen mode

Additional Resources / Info

JMeter test results are captured as artifacts for each Workflow Run in GitHUB actions.
This is useful because it's a way to share the test results with your team. They just download the test results and they can see the results.

Top comments (1)

Collapse
 
sebiboga profile image
Boga Sebastian Nicolae • Edited

I changed a little bit the script, just in case you want to keep in artifacts also the JTL files generted. So before saving the artifact, I just added this script to the Github Actions:

      - name: move jtl files to test_report
        run: |
         mv *.jtl $GITHUB_WORKSPACE/test_report
Enter fullscreen mode Exit fullscreen mode

You can see the full YML file here:

# This is a workflow to help you run all JMeter scripts with Actions, and save Test Results as artifact
name: jmeter_test_results
# Controls when the workflow will run
on:
  # Triggers the workflow on push or pull request events but only for the main branch
  push:
    branches: [ main ]

  # Allows you to run this workflow manually from the Actions tab
  workflow_dispatch:

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
  # This workflow contains a single job called "build"
  build:
    # The type of runner that the job will run on
    runs-on: ubuntu-latest
    # Steps represent a sequence of tasks that will be executed as part of the job
    steps:
      # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
      - uses: actions/checkout@v2
      - name: where are the files?
        run: |
           pwd
           ls
      - name: create test_report
        run: |
           mkdir $GITHUB_WORKSPACE/test_report
       # Runs a set of commands using the runners shell
      - name: install jmeter
        run: |
          java -version
          wget https://downloads.apache.org//jmeter/binaries/apache-jmeter-5.4.1.zip
          unzip apache-jmeter-5.4.1.zip
          cd apache-jmeter-5.4.1/bin
          ./jmeter -v
          pwd
      - name: install plugins
        run: |
          cd $GITHUB_WORKSPACE/apache-jmeter-5.4.1
          wget -q --no-check-certificate https://jmeter-plugins.org/files/packages/jpgc-dummy-0.4.zip  -P .
          unzip -o jpgc-dummy-0.4.zip  && rm jpgc-dummy-0.4.zip
      - name: run jmx scripts
        run: |
         cd $GITHUB_WORKSPACE
         for i in $( ls -A1 *.jmx); do
            cd $GITHUB_WORKSPACE/apache-jmeter-5.4.1/bin
            mkdir $GITHUB_WORKSPACE/test_report/${i%.jmx}
            ./jmeter -n -t $GITHUB_WORKSPACE/$i  -l $GITHUB_WORKSPACE/${i%.jmx}.jtl -e -o $GITHUB_WORKSPACE/test_report/${i%.jmx}
         done
      - name: move jtl files to test_report
        run: |
         mv *.jtl $GITHUB_WORKSPACE/test_report
      - name: Upload JMeter Test Results
        uses: actions/upload-artifact@v2.2.4
        with:
         name: test_results
         path: test_report
Enter fullscreen mode Exit fullscreen mode