如何将GITHub参数作为用户定义的变量传递给Jmeter

oyjwcjzk  于 2022-11-09  发布在  Git
关注(0)|答案(1)|浏览(159)

你好,我想执行我的JMX脚本到GITHUB,我可以执行,但是我的问题是在传递参数到我的Jmeter时它不工作。这是我的yaml文件。非常感谢你的回复。非常感谢
名称:CI
打开:推送:分支:[“主”] pull_request:分支:[“main”]
工作流分派:输入:选择:类型:选项描述:环境选项:- foo -酒吧-巴兹
作业:
构建:运行:最新ubuntu

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

输出:一旦我从GIT中选择了值,它将传递给Jmeter并在执行中使用。
仅供参考:我尝试使用此变量${{ inputs.choice }}=${choice}或${{ github.event.inputs.choice }}=${choice},但它在我这边不起作用。
截图:

ha5z0ras

ha5z0ras1#

除非你停止从互联网上复制和粘贴解决方案,而不了解他们在做什么,并忽视社区的建议,否则任何事情都不会“对你”有效。
正确的语法为:

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

完整的YAML文件,以防万一:

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的配置:

证明其有效的证据:

更多信息:

相关问题