You can integrate mabl with your GitLab CI/CD pipelines easily using mabl's prebuilt GitLab pipeline images.
The GitLab pipeline integration lets you:
- Easily trigger mabl tests from your CI/CD pipeline
- See mabl test result summaries as a pipeline stage
- Review mabl test results in merge requests
Should I use the GitLab Integration or mabl-cli image?
This integration is meant to automatically add mabl test result information to your GitLab Merge Requests, and easily integration with GitLab CI/CD Pipelines. If, however, you want to use all the possible features of the mabl test triggering APIs, consider using the Mabl CLI Docker image, or install the mabl CLI overview directly in your Pipeline.
You will need to add the following pipeline stage to your
.gitlab-ci.yml in the pipeline you wish to run mabl tests. The operative section is the
run-mabl-tests section below:
Tying build success to mabl test success
The mabl build stage will emit a non-zero exit code when mabl tests fail. This will trigger your pipeline to be marked as "failed" in GitLab. To avoid this, set the
MABL_FAIL_STAGE_ON_TEST_FAIL='false'in your stage
build-1: stage: build script: - echo "Building your code" - echo "Place your build code here" # Add this build stage to your pipeline YAML run-mabl-tests: image: mablhq/gitlab-integration:latest stage: test variables: # Use 'mabl deployments create --help' on @mablhq/mabl-cli to learn more about flags MABL_TEST_SELECTORS: "--application-id=<YOUR-APP-ID> --labels=gitlab-demo" script: - "./mabl/home/run.sh" only: - merge_requests - branches except: - main deploy-1: stage: deploy script: - echo "Deploying code to production" - echo "Place your deployment code here"
You can customize the action taken by the integration by test selector flags from the mabl CLI
deployments create command in the
MABL_TEST_SELECTORS environment variable, including:
--application-idto choose an application to test
--environment-idto choose an environment to test
--labelsto run plans that match any supplied label
--urlto pass a URL override for test execution
--environment-id must be passed
Working with Preview Environments / Review Apps
You need to create an
api scoped Personal Access Token so that mabl can update your merge requests. To do this, visit the Personal Access Tokens section of GitLab and create a key called
Mabl Access Token, as pictured below.
Be sure to save the token value.
You can find your mabl API access key in mabl under
Settings > API. If you don't already have a CLI scoped key, see the Advanced API Key Management documentation for how to create and manage keys.
You need to save the necessary secrets to the project your CI/CD pipeline will run under.
Project > Settings > CI/CD > Variables
- Add the variable
MABL_GITLAB_API_TOKENand set it to the personal access token created above.
- Add the variable
MABL_REST_API_KEYand set it to your mabl API key.
Unless you are using Protected Branches/Tags (learn more), uncheck the Protected option.
It's often useful to run feature branch tests on a branch of mabl tests. By default, the GitLab integration will detect your GitLab build branch, and (1) automatically create a mabl test branch of the same name and (2) execute your mabl test run against that branch. This will only happen if mabl can detect your branch from GitLab supplied metadata.
This detected branch is visible in your mabl test results, as shown below.
Auto-branching support may be disabled by either
--branch-name=your-preferred-nameto the script variable
- OR setting the script variable
Now, depending on the configuration of your GitLab CI/CD Pipeline, when your mabl tests stage runs, you'll be able to:
- See that the run started as a comment in your merge request
- See the live status of the running tests in your pipeline job page
- See the output of your tests in Markdown on your merge request when they finish
- Fail your build if your mabl tests fail (optional)
MABL_AUTO_BRANCH_ENABLEDenvironment flag input, allowing disabling auto-branching support
truefor debugging info)
- Fixed bug where auto-branching combined with explicit branching caused failure to execute commands
- Fixed bug where zero exit code could be emitted on failure
- Added additional helpful logging to explain auto-branching support
- Added additional error handling safeguards
- Fixed bug where command would not execute of image default path had was altered
- Dependency updates
- mabl-cli version upgrade
- Initial public release
Updated 11 months ago