CODEFRESH.IO DOCUMENTATION

Codefresh is a Docker-native CI/CD platform.

Instantly build , test and deploy Docker images.

Search results for "{{ search.query }}"

No results found for "{{search.query}}". 
View All Results

Variables

Variables in the YAML follow this format: ${{VAR_NAME}}.
The flow provides three forms of variable substitution:

  • system provided: substituted during the workflow compilation phase.
  • context related: substituted in real time during the workflow execution.
  • custom user provided: created and substituted in real time during the workflow execution

System Provided Variables

All system provided variables will also be automatically injected to any freestyle step.

Variable
Description

${{CF_REPO_OWNER}}

Repository owner.

${{CF_REPO_NAME}}

Repository name.

${{CF_BRANCH}}

Branch name of the Git repository of the main pipeline, at the time of execution.

You can also use ${{CF_BRANCH_TAG_NORMALIZED}} to get the branch name normalized. It will be without any chars that are illegal in case the branch name were to be used as the Docker image tag name.

${{CF_COMMIT_AUTHOR}}

Commit author.

${{CF_COMMIT_URL}}

Commit url.

${{CF_COMMIT_MESSAGE}}

Commit message of the git repository revision, at the time of execution.

The messages quotes are escaped (i.e. ' is not \', " is now \").

${{CF_REVISION}}

Revision of the Git repository of the main pipeline, at the time of execution.

You can also use ${{CF_SHORT_REVISION}} to get the abbreviated 7-character revision hash, as used in git. Note: use this variable as string with quotes to tag the image '${{CF_SHORT_REVISION}}'

${{CF_VOLUME_NAME}}

Will refer to the volume that was generated for the specific flow. Can be used in conjunction with a composition to provide access to your cloned repository.
For example:
test-server:
volumes:

- ${{CF_VOLUME}}:/cloned/repo

${{CF_VOLUME_PATH}}

Will refer to the mounted path of the workflow volume inside a Freestyle container.

${{CF_BUILD_TRIGGER}}

Will be an indication of the current build was triggered:

  • build: The build was triggered from the build button
    • webhook: The build was triggered from a control version webhook

${{CF_BUILD_ID}}

The build id. Note: use this variable as string with quotes to tag the image '${{CF_BUILD_ID}}'

${{CF_BUILD_TIMESTAMP}}

The timestamp the build was created. Note: use this variable as string with quotes to tag the image '${{CF_BUILD_TIMESTAMP}}'

${{CF_BUILD_URL}}

The URL to the build in Codefresh

${{CF_KUBECONFIG_PATH}}

Path to kubeconfig if exist

Any variable specified in the pipeline settings

For example, if you configure the pipeline settings with a variable named PORT, you can put the variable in your YAML build descriptor as ${{PORT}}.

Context Related Variables

Context related variables are created dynamically during the workflow execution and according to the used steps.

Variable
Description

Working Directories

For example, you can set the working directory of step A with a variable named after a previously executed step, step B. Therefore, setting step A with working-directory:${{B}} means that step A executes in the same working directory as step B.

Images

You can set the candidate field of the push step with a variable named after a previously executed build step. Since the details of a created image are not necessarily known ahead of time, the variable can create an association to an optionally dynamic image name. Therefore, setting push step A with candidate:${{B}} means that step A will push the image build buy step B.

Custom User Provided Variables

Custom variables can be created during the workflow execution inside of a freestyle step.
Once a variable has been created it will:

  • automatically be injected into any future freestyle step.
  • automatically be used as composition variables for composition steps.
  • will be used for substitutions in the yaml file just like the system provided variables are used in the compilation phase.

Custom variables are wiped clean on every pipeline execution, but are not modified as the steps progress.

exporting environment variables from a freestyle step

In case you want to export environment variables from an existing step this is the way to do it

Codefresh exposes a file for each freestyle step that custom variables can be registered to.
There are two ways to add variables to this file

Custom Variables Option a: Using cf_export cli

In case your freestyle step has sh installed, you can use our prepared cli that will enable you to easily add new variables.

You can either:

  • explicitly state a VAR=VAL pair
  • state the name of an existing environment variable (like EXISTING_VAR).
version: '1.0'
steps:
  freestyle-step-1:
    description: Freestyle step..
    title: Free styling
    image: alpine:latest
    commands:
        - cf_export VAR1=VALUE1 VAR2=VALUE2 EXISTING_VAR
    	
  freestyle-step-2:
    description: Freestyle step..
    title: Free styling 2
    image: ${{VAR1}}
    commands:
        - echo $VAR2
        - curl http://$EXISTING_VAR/index.php

Custom Variables Options b: Manually appending to the file

Appending variables manually can be useful in more complicated scenarios.

The variables file will be exposed inside the freestyle container in the following path: ${{CF_VOLUME_PATH}}/env_vars_to_export

You can use this technique to even inject a file with multiple variables.

version: '1.0'
steps:
  freestyle-step-1:
      description: Freestyle step..
      title: Free styling
      image: alpine:latest
      commands:
          - echo VAR1=192.168.0.1 >> ${{CF_VOLUME_PATH}}/env_vars_to_export
          
  freestyle-step-2:
    	description: Freestyle step..
    	title: Free styling 2
    	image: ${{hey}}
    	commands:
    		- curl http://$VAR1/index.php

Escape Characters

When passing special characters through environmental variables \ can be used as an escape character. For example if you were passing a cassandra connection string you might do something like Points\=hostname\;Port\=16376\;Username\=user\;Password\=password

This will safely escape ; and =.

Variables