Step 1: Initialize all Environment Variables

A CI/CD pipeline usually depends on a number of predefined environment variables. There are a few ways to define these variables. For example, some of them can be set at the CI/CD platform level, secrets should be set in chamber , while other values should be set directly in the codefresh.yml configuration.

See the Codefresh shared configuration documentation for an example.

Our “best practice” is to store all non-secrets directly in the codefresh.yml configuration file. This solution allows us to easily keep track of the history with git as values change over time and let them vary by branch. To accomplish this, set all the predefined values in a step called init_variables that calls cf_export to pass them to subsequent steps.

Dependencies

None

Examples

Init variables with Codefresh

version: '1.0'

steps:
  init_variables:
    title: Init variables
    image: alpine
    commands:
    - cf_export BUILD_HARNESS_VERSION=0.5.5
    - cf_export CF_BUILD_UNIX_TIMESTAMP=$(expr ${{CF_BUILD_TIMESTAMP}} / 1000)
    - cf_export GIT_BRANCH=${{CF_BRANCH}}
    - cf_export BASE_HOST=us-west-2.staging.example.com
    - cf_export NAMESPACE=pr-${{CF_PULL_REQUEST_NUMBER}}-${{CF_REPO_NAME}}
    - cf_export APP_HOST=pr-${{CF_PULL_REQUEST_NUMBER}}.${{CF_REPO_NAME}}.us-west-2.staging.example.com