Using Tidelift with Gitlab Pipelines

This article shows how to use the Tidelift CLI with Gitlab Pipelines to check catalog alignment during a build stage. This allows builds to fail that include unapproved packages as of a CI/CD process.

To get started, you will need:

  • A Tidelift Subscription (Please contact us if you are interested in learning more about Tidelift)
  • A Gitlab account which can access Tidelift

With the appropriate configuration, Gitlab can use the Tidelift CLI to run an alignment as part of a pipeline. For each Tidelift project, you can create a project and API key in Tidelift and store that key in the appropriate secrets infrastructure provided by your CI system.

An organization-level API key can also be created which is only scoped to run alignments, but works across all projects. In this example, the API key is stored as a secret variable. Next, you need to add steps to your pipeline job that set the Tidelift API Key, checkout code from version control, download the Tidelift CLI, and run an alignment with the Tidelift CLI.

Create a project in Tidelift and generate an API key in the Tidelift webapp

After logging into the Tidelift Subscription dashboard:

  1. Select Projects
  2. Click on Create New Project
  3. Enter the project name and remember that spaces, periods, or slashes are not valid naming characters in project names
  4. When prompted, select the catalog you want the project to align with

    Screen_Shot_2021-12-22_at_2.50.21_PM.png

  5. Close the Upload manifest files dialog to skip manually uploading manifests
  6. Select the Projects actions and settings gear on the left navigation
  7. Select Get Project Key then select Create Project Key

    Screen_Shot_2021-12-22_at_2.52.06_PM.png
  8. Copy the CI/CD usage API_KEY and note the Organization-name/project-name

Screen_Shot_2021-12-22_at_2.52.51_PM.png

In the above example:

  • organization-name: "souza-weisberg-holdings"
  • project-name: "gitlab-test-project"


Add the API Key to the Gitlab Pipeline Job

NOTE

Always check with your Security Administrators to ensure you are following your companies policies for securing and storing secrets.

In this example, the Tidelift API key is saved as a masked variable. This can be done from the Gitlab project settings page under CI/CD>variables. Name the variable and past the API key into the value field. Make sure the select masked to keep the API key from printing in server logs.

Screen_Shot_2021-12-22_at_3.07.04_PM.png



Add pipeline job step to check alignment with Tidelift

In Gitlab Pipelines:

  1. Select the pipeline to use the Tidelift CLI with
  2. Add a job with the steps to set the Tidelift API Key
  3. Checkout code from version control
  4. Download the Tidelift CLI
  5. Run an alignment with the Tidelift CLI

gitlab-ci.yml example:

build-job:
  stage: build
  image: ruby # other Debian-based images may work, the CLI requires glibc.
  variables:
    TIDELIFT_API_KEY: $TIDELIFT_API_KEY_PROTECTED_VARIABLE # this should be kept
in a GitLab Protected Variable
https://docs.gitlab.com/ee/ci/variables/#create-a-custom-variable-in-the-ui
script: - echo "Downloading Tidelift CLI" - curl https://download.tidelift.com/cli/tidelift -o tidelift - echo "Setting permissions" - chmod +x tidelift - echo "Runnning alignment and saving to Tidelift" - ./tidelift alignment save --wait

Note: The Tidelift CLI will attempt to detect the branch of the pipeline automatically in CLI v1.3.0 and later. If the branch can not be detected, the branch will need to be specified using the branch flag. Please see the CLI reference for more information.

Once the required job steps have been added to the pipeline, select Save. Test the new pipeline configuration by selecting Run pipeline from pipelines dashboard. Any unapproved packages that are included in the pipeline will cause the check to fail. The output will include a Tidelift link with more info and actions a developer can take to either request new packages or switch to already-approved releases.

Was this article helpful?
0 out of 0 found this helpful

Comments

0 comments

Article is closed for comments.

Articles in this section