Home > Software design >  How to pass GITHub parameters to Jmeter as user defined variable
How to pass GITHub parameters to Jmeter as user defined variable

Time:08-17

Hello I want to execute my JMX script to GITHUB and I'm able to execute, however my problem is upon passing that parameter to my Jmeter it doesn't work. Here's my yaml file. Your response is highly appreciated. Thank you so much

name: CI

on: push: branches: [ "main" ] pull_request: branches: [ "main" ]

workflow_dispatch: inputs: choice: type: choice description: Environment options: - foo - bar - baz

jobs:

build: runs-on: ubuntu-latest

steps:
  - uses: actions/checkout@v3

  - name: setup-jmeter
    run: |
      sudo apt-get update
      sudo apt install curl -y
      sudo apt install -y default-jdk
      sudo curl -O https://archive.apache.org/dist/jmeter/binaries/apache-jmeter-5.3.tgz 
      sudo tar -xvf apache-jmeter-5.3.tgz
      cd $GITHUB_WORKSPACE/apache-jmeter-5.3/lib && sudo curl -O https://repo1.maven.org/maven2/kg/apc/cmdrunner/2.2.1/cmdrunner-2.2.1.jar
      cd $GITHUB_WORKSPACE/apache-jmeter-5.3/lib/ext && sudo curl -O https://repo1.maven.org/maven2/kg/apc/jmeter-plugins-manager/1.6/jmeter-plugins-manager-1.6.jar
      cd $GITHUB_WORKSPACE/apache-jmeter-5.3/lib && sudo java -jar cmdrunner-2.2.1.jar --tool org.jmeterplugins.repository.PluginManagerCMD install-all-except jpgc-hadoop,jpgc-oauth,ulp-jmeter-autocorrelator-plugin,ulp-jmeter-videostreaming-plugin,ulp-jmeter-gwt-plugin,tilln-iso8583
  - name: run-jmeter-test
    run: |
      echo "choice is ${{ github.event.inputs.choice }}" / ${{ inputs.choice }}
      $GITHUB_WORKSPACE/apache-jmeter-5.3/bin/./jmeter.sh -n -t Example-Demo.jmx -Jchoice=${choice} -l result.jtl 
      
      
  - name: Upload Results
    uses: actions/upload-artifact@v2
    with:
      name: jmeter-results
      path: result.jtl

Output: Once I selected the value from GIT, it will pass to Jmeter and use on the execution.

FYI: I tried to use this variable ${{ inputs.choice }}=${choice} or ${{ github.event.inputs.choice }}=${choice} but it doesn't work on my end.

Screenshot:

enter image description here

enter image description here

CodePudding user response:

Nothing will work "on your end" until you stop copying and pasting solutions from the Internet without understanding what they're doing and ignoring recommendations from the community.

The correct syntax would be:

-Jchoice="${{ github.event.inputs.choice }}"

Full YAML file just in case:

name: CI

on:
  push:
    branches: [ "main" ]
  pull_request:
    branches: [ "main" ]

  workflow_dispatch:
    inputs:
      choice:
        type: choice
        description: foo
        options:
        - foo
        - bar
        - baz

jobs:

  build:

    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v3

      - name: setup-jmeter
        run: |
          sudo apt-get update
          sudo apt install curl -y
          sudo apt install -y default-jdk
          sudo curl -O https://archive.apache.org/dist/jmeter/binaries/apache-jmeter-5.3.tgz 
          sudo tar -xvf apache-jmeter-5.3.tgz
          cd $GITHUB_WORKSPACE/apache-jmeter-5.3/lib && sudo curl -O https://repo1.maven.org/maven2/kg/apc/cmdrunner/2.2.1/cmdrunner-2.2.1.jar
          cd $GITHUB_WORKSPACE/apache-jmeter-5.3/lib/ext && sudo curl -O https://repo1.maven.org/maven2/kg/apc/jmeter-plugins-manager/1.6/jmeter-plugins-manager-1.6.jar
          cd $GITHUB_WORKSPACE/apache-jmeter-5.3/lib && sudo java -jar cmdrunner-2.2.1.jar --tool org.jmeterplugins.repository.PluginManagerCMD install-all-except jpgc-hadoop,jpgc-oauth,ulp-jmeter-autocorrelator-plugin,ulp-jmeter-videostreaming-plugin,ulp-jmeter-gwt-plugin,tilln-iso8583

      - name: run-jmeter-test
        run: |
          $GITHUB_WORKSPACE/apache-jmeter-5.3/bin/./jmeter.sh -Jchoice="${{ github.event.inputs.choice }}" -n -t test.jmx -l result.jtl

JMeter's configuration:

enter image description here

Evidence that it's working:

enter image description here

More information:

  • Related