Mark T
Mark T

Reputation: 13

Fail GitHub Actions Pipeline if Dockerized Jmeter tests failed

I was hoping to get some advice on the following problem:

I have built a simple CI/CD pipeline in GitHub Actions and I am trying to execute my Jmeter tests inside a Docker container. I am using justb4/jmeter image and I essentially just copy my jmx file from my GitHub repository into /opt/apache-jmeter-5.3/bin, so that I could execute the tests in my container. My problem is that even if Jmeter tests fail inside the container my pipeline continues to execute and does not detect this failure.

How can I stop the pipeline from further execution if my Jmeter tests failed in a Docker container?

Any help is much appreciated, Mark

Upvotes: 1

Views: 749

Answers (2)

Tushar Rajpoot
Tushar Rajpoot

Reputation: 11

Check my action for installing jmeter inside your workflow.

https://github.com/marketplace/actions/setup-jmeter

name: Test Action
on:
  push
jobs:
  test-action:
    runs-on: ubuntu-latest
    steps:
      - name: Setup Jmeter
        uses: tush-tr/[email protected]

Upvotes: 0

Dmitri T
Dmitri T

Reputation: 168002

In order to be able to fail the step you need to return non-zero exit status code, the options are in:

  1. Use JMeter Maven plugin, if you add jmeter-check-results action like:

    <execution>
        <id>jmeter-check-results</id>
        <goals>
            <goal>results</goal>
        </goals>
    </execution> 
    

    the failed maven build will be caught by Github Actions

  2. Use Taurus tool as a wrapper, Taurus can also be run as a docker image and it has Pass/Fail Criteria subsystem which has flexible criteria allowing conditional failing the test, in case of test failure Taurus returns non-zero exit status code and it will be sufficient for failing the pipeline step

  3. This option requires minimal changes but it's least powerful. Add JSR223 Listener to your Test Plan and put the following code into "Script" area:

    if (!prev.isSuccessful()) {
        System.exit(1)
    }     
    

    it will force JMeter exit on any Sampler failure (however depending on your JMeter configuration you may loose a part of results)

Upvotes: 0

Related Questions