The following example shows how to use Momentic with GitLab CI.

For more usage examples, see the momentic-ai/examples repository.

For a given root package.json:

package.json
{
  "name": "my-momentic-repo",
  "scripts": {
    "install-browsers": "momentic install-browsers --all",
    "test": "momentic run",
    "upload-results": "momentic results upload test-results"
  },
  "devDependencies": {
    "momentic": "latest"
  }
}

Create a file called gitlab-ci.yml in your repository with the following contents:

gitlab-ci.yml
image: node:latest
stages:
  - build
build:
  stage: build
  script:
    - npm install
    - npm run install-browsers
    - npm run test
  after_script:
    - npm run upload-results

Authentication

To run any commands, you must authenticate with Momentic. You can do this by adding the MOMENTIC_API_KEY environment variable to your GitLab CI workflow.

  1. Create an API key in Momentic Cloud.

Copy the value to a safe place. You’ll need it in a moment.

  1. Go to your GitLab repository settings and click on the Settings and then CI/CD tab. Create a new variable called MOMENTIC_API_KEY and enter the value of your API key.
  1. GitLab CI automatically loads environment variables stored in project settings into the CI environment. No modifications are necessary for the CI file.