GitLab CI/CD Integration¶
In this guide we'll show you how to set up a GitLab CI/CD pipeline so that Mayhem can automatically test your code or API on every push.
You will need the following to run Mayhem in your GitLab CI/CD pipeline:
- Create a Mayhem API token.
- Add the newly created token as a "Secret Variable" in the pipeline's variables named
MAYHEM_TOKEN
.
Pipeline Configuration for Mayhem with GitLab CI/CD¶
Create a .gitlab-ci.yml
file to configure a GitLab CI/CD pipeline and test your code or API:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
|
Integrating Mayhem with GitLab CI/CD¶
Now that we've shown you the .gitlab-ci.yml
file that you'll need to properly integrate Mayhem with GitLab CI/CD, let's walk through a working example.
Info
For this example we are forking the assets located at mcode-action-examples and integrating Mayhem into the GitLab CI/CD pipeline for the underlying targets.
To get the config working in GitLab, you will have to first set up the Secret Variables. For this example, we've set the following pipeline variables:
MAYHEM_TOKEN
: Your user generated Mayhem API token.MAYHEM_URL
: The URL to the Mayhem server. Here we sethttps://app.mayhem.security
.
In addition, for the above .gitlab-ci.yml
configuration, we build and push our Docker image to the GitLab Container Registry. Therefore, make sure to set your project's visibility to Public
to allow Mayhem to pull from the GitLab Container Registry for the repository Docker image.
Once you've completed the above steps, you should be able to run the GitLab CI/CD pipeline, which will execute a Mayhem run against the underlying targets to test for vulnerabilities.