CloudTruth Documentation
Sign InAPIIntegrationsGitHubVisit our website
  • Overview
  • Getting Started
  • Architecture
    • 🔒Security Overview
  • Copilot
  • 🏢Org management
    • Account Setup
    • Access Control
      • 🔑API Tokens
      • 🌐Protecting Projects and Environments
      • 👥Users
    • Audit Log
  • 🛠️Config Management
    • Projects
    • Parameters
      • Sharing Config Data
      • Parameter Management
        • Internal Values
          • Dynamic Values
        • External Values
          • Terraform Remote State Files
        • Parameter Override
        • Environment Value Override
      • Parameter and Parameter Value Inheritance
      • Value Comparison
      • Value History
      • Value Validation
      • Value Expiration
    • Environments and Tags
    • Templates
      • 📒Sample Templates
    • Actions
      • Import Actions
      • Push Actions
    • CLI & API
      • CloudTruth CLI
      • Rest API
    • Integrations
      • Argo CD
      • Atlassian Compass
      • AWS
        • AWS Connection
        • AWS Role
          • CloudFormation
          • Terrraform
          • AWS Console
        • Parameter Store (SSM)
        • S3
        • Secrets Manager
      • Azure Key Vault
      • Bitbucket Pipelines
      • Docker
      • Docker Compose
      • GitHub
      • GitHub Actions
      • GitLab
      • Harness
      • Jenkins
      • Kubernetes
      • Pulumi
      • Terraform
      • Terragrunt
      • Explorer
      • Circle CI
    • Events, Notifications, Webhooks
    • Types
  • 🔎REPORTING
    • Compare
    • History
    • Expirations
  • 🚀PRODUCT
    • What is CloudTruth?
    • Interactive Demo
    • Kubernetes
    • Terraform
    • CI/CD Pipeline Configuration
    • Cloud CMDB
    • Secrets Management
    • GitOps
    • Our Manifesto
    • Open Source
    • FAQs
    • Our Mission
  • 📚Reference
    • 🎓Quick Start Videos
      • What is CloudTruth?
      • CloudTruth in Action
      • Environments and Projects
      • Secrets, Parameters, ENV variables
      • Audit Logs, RBAC, SSO
      • Containers - Kubernetes, Docker
      • Infrastructure as Code (IaC) - Terraform, Cloudformation, CDK, Azure Bicep, Pulumi
      • CICD Pipelines - GitHub Actions, ArgoCD, Jenkins, CircleCI, Harness, GitLab Pipelines
      • AWS Videos - Secret Manager, Parameter Store, S3, IAM
      • Azure Videos - Azure DevOps, Azure Bicep, PowerShell
    • Knowledge Base
      • Best Practices
        • Versioned Releases
      • CLI
        • History comparison of deleted parameters with null values
      • Integrations
        • Advanced AWS IAM policy permissions
        • K8s pull image from private Docker registry
        • S3 Region Selection
      • Templates
        • Templates render quotations in key values as quot
    • Roadmap and New Features
    • JMESPath Reference
    • REST API
Powered by GitBook

Copyright© 2023 CloudTruth

On this page
  • Prerequisites
  • Provide GitLab Access
  • Configure a CI/CD pipeline with CloudTruth Parameters

Was this helpful?

  1. Config Management
  2. Integrations

GitLab

PreviousGitHub ActionsNextHarness

Last updated 2 years ago

Was this helpful?

This walkthrough shows you how to use CloudTruth parameters with GitLab CI /CD jobs.

Prerequisites

  • You have a .

  • You have created one or more .

  • You have created a .

Provide GitLab Access

Add your generated CloudTruth API Access token as a GitLab variable called CLOUDTRUTH_API_KEY in your project settings. This allows the GitLab project to securely access parameters stored in CloudTruth.

Configure a CI/CD pipeline with CloudTruth Parameters

Install the CloudTruth CLI with a Build Stage

You can install the CLI with the following code snippet in a GitLab build stage. This will install the latest supported version and also verify the CLI is installed correctly by printing the version.

Install CloudTruth CLI:
  stage: build
  script:
    - curl -sL https://github.com/cloudtruth/cloudtruth-cli/releases/latest/download/install.sh | sh
    - cloudtruth -V 

Passing CloudTruth parameters to GitLab test stages

    # Adds CloudTruth Values to build.env file to be passed with artifacts.reports.dotenv
    - echo "FLASK_RUN_PORT=$(cloudtruth --project MyFirstProject --env default parameters get FLASK_RUN_PORT)" >> build.env
    - echo "FLASK_MESSAGE=$(cloudtruth --project MyFirstProject --env default parameters get FLASK_MESSAGE)" >> build.env
  
  # Passes environment variables between stages
  artifacts:
    reports:
      dotenv: build.env

Using CloudTruth parameters in test stages

Now you can reference the variables in downstream stages.

Using CloudTruth Variables:
  stage: test
  script:
    - echo $FLASK_RUN_PORT
    - echo $FLASK_MESSAGE
  dependencies:
    - "Install CloudTruth CLI"

Running this pipeline will install the CloudTruth CLI and print the parameter values.

The complete .gitlab-ci.yml

Install CloudTruth CLI:
  stage: build
  script:
    - curl -sL https://github.com/cloudtruth/cloudtruth-cli/releases/latest/download/install.sh | sh
    - cloudtruth -V 
    
    # Adds CloudTruth Values to build.env file to be passed with artifacts.reports.dotenv
    - echo "FLASK_RUN_PORT=$(cloudtruth --project MyFirstProject --env default parameters get FLASK_RUN_PORT)" >> build.env
    - echo "FLASK_MESSAGE=$(cloudtruth --project MyFirstProject --env default parameters get FLASK_MESSAGE)" >> build.env
  
  # Passes environment variables between stages
  artifacts:
    reports:
      dotenv: build.env

Using CloudTruth Variables:
  stage: test
  script:
    - echo $FLASK_RUN_PORT
    - echo $FLASK_MESSAGE
  dependencies:
    - "Install CloudTruth CLI"

Parameter export

sed -i '/^$/d' build.env

Install CloudTruth CLI:
  stage: build
  script:
    - curl -sL https://github.com/cloudtruth/cloudtruth-cli/releases/latest/download/install.sh | sh
    - cloudtruth -V

    
    # Adds CloudTruth Values to build.env file to be passed with artifacts.reports.dotenv
    - cloudtruth --project MyFirstProject parameter export docker  >> build.env
    - sed -i '/^$/d' build.env
      
  # Passes environment variables between stages
  artifacts:
    reports:
      dotenv: build.env

Using CloudTruth Variables:
  stage: test
  script:
    - printenv

  dependencies:
    - "Install CloudTruth CLI"

Take caution building environment variables that contain secret values as they can be exposed in your pipeline. Parameter export redacts secret values by default.

In the build stage, we can access and pass variables to GitLab with . This snippet will add environment variables FLASK RUN PORT and FLASK_MESSAGE to build.env with values pulled from CloudTruth.

Alternatively you can use the CloudTruth parameter export command to create a . GitLab pipelines will fail to upload a .env file if it has a newline at the end of the file. We will use a sed command in the job to strip the export of empty lines.

🛠️
artifacts
GitLab .env file
GitLab account
CloudTruth Parameters
CloudTruth API Access token