Integration with GitLab

  • 17 January 2023
  • 0 replies
  • 611 views

 

With our CI integration to GitLab you can automatically upload your latest commits and pull requests to Debricked whenever you run your pipeline. Our GitLab integration support the same options as our Bitbucket integration, read more about the options here: https://bitbucket.org/debricked/debricked-scan

We support both the cloud version and the self-hosted version of GitLab.

 

Configure Debricked token

Start by generating an access token. Copy the token so that you can use it in the next step.

Configure your DEBRICKED_TOKEN:

  1. Head over to your Repository
  2. Go to Settings -> CI/CD 
  3. Expand the Variables field
  4. Paste in the access token from the previous step. Make sure to mask the token, so that it does not show in the logs!

 

Configure GitLab CI/CD job

Depending on what package manager you are using there are different job setups.

In order for us to analyze all dependencies in your project, their versions, and relations, files containing the resolved dependency trees have to be created prior to scanning. Those depend on the package manager used. If files are lacking we try to generate them on our side, which can negatively affect speed and accuracy.

Example 1: If npm is used in your project you will have a package.json file, but in order for us to scan all your dependencies we need either package-lock.json or yarn.lock as well.

Example 2: If Maven is used in your project you will have a pom.xml file, but in order for us to resolve all your dependencies we need a second file, as Maven does not offer a lock file system. Instead, Maven dependency:tree plugin can be used to create a file called .debricked-maven-dependencies.tgf.

 

  1. Add the template to your .gitlab-ci.yml file (if the file doesn't exist, create one)
  2. Commit your changes to .gitlab-ci.yml and watch the CI run!

Integrate many repositories using one configuration with GitLab

Integrating many repositories with one configuration using GitLab can greatly simplify the process of managing and deploying code across multiple projects.

You can set this up with multi-project pipelines:

  1. Start by generating an access token

  2. In GitLab, create a file in a new or existing repository and paste the Debricked template contents from https://github.com/debricked/cli/blob/main/examples/templates/GitLab/gitlab-ci.yml

  3. To avoid having to add the DEBRICKED_TOKEN to every integrated repository, it is possible to set up the token as a var for either:
    - a group of projects
    - your entire instance

  4. Trigger it in target project(s) by adding the following code and adjusting the reference to point to the file created in step 2:

    debricked-scan:
    trigger:
    include:
    - project: '<org_name>/<repository_name>'
    ref: '<branch_name>'
    file: '/path/to/file.gitlab-ci.yml'
    strategy: depend

     

  5. Done!

 

Credentials for merge requests

Debricked can generate merge requests for you, but to be able to use it in GitLab, you also need to provide us with credentials, so that we can create the merge request on your GitLab instance.

You can use either:

  • Personal access tokens

  • Project-scoped access tokens (currently available in paid versions of Gitlab), unique for every project

 

You can generate a Personal access token by going to the User settings. You need to grant the token the api scope.

Then when you try to create a Merge Request inside the Debricked tool, it will automatically ask you for your credentials when needed.

After clicking Confirm, the merge request generation should start.


 


0 replies

Be the first to reply!

Reply