Scanning
GitLab

GitLab

This guide shows you how to integrate Coana with GitLab CI/CD.

Generate an API key

Go to Settings → API Keys (opens in a new tab) to generate an API key.

Add the generated API key as a project variable

Add the generated API key to your project by creating a project variable with the name COANA_API_TOKEN at the following URL: https://gitlab.com/org/projectName/-/settings/ci_cd (opens in a new tab). Make sure to replace 'org' and 'projectName' with your organization's name and your repository's name.

You can also create an organization-wide variable by navigating to the organization settings and adding the variable there. The organization-wide variable will be available to all projects in the organization, so it's usually a better option if you need to run Coana on many projects.

💡

For security reasons we recommend that you check the mask variable checkbox when adding the COANA_API_TOKEN variable.

Create the workflow file

Create a .gitlab-ci.yml file in the root of your repository with the content below. If you already have an existing .gitlab-ci.yml you just need to add the coana-ci job to it. It's not necessary to compile or bundle your code prior to running Coana.

.gitlab-ci.yml
image: node:20
 
stages: 
  - coana
 
coana-ci:
  stage: coana
  image: coana/coana:latest
  rules: 
    - if: $CI_PIPELINE_SOURCE == "schedule"
  dependencies:
    - install
  script:
    - coana run . --repo-url $CI_PROJECT_URL --api-key $COANA_API_TOKEN
💡
A new project is automatically created in Coana when you submit your first report if a project matching its repository url or project name dosen't already exist. There is no reason to manually create the project in Coana first.

You don't need to install project dependencies, such as running npm install, before using Coana, as Coana will handle the installation of the dependencies for you. However, if you have specific requirements for the installation command, we recommend adding an entry to the script: array to install the dependencies manually.

Configure Coana to run on a fixed schedule

Open your project's page in GitLab. Select 'Build', 'Pipeline schedules' and then 'New schedule'. Set the interval pattern to your preferred settings. We recommend running Coana at least once a day.