Examples of variables
The following examples show how to define and reference variables in the workflow definition file.
For more information about variables, see Using variables in workflows.
Examples
- Example: Defining a variable using the Inputs property
- Example: Defining a variable using the Steps property
- Example: Exporting a variable using the Outputs property
- Example: Referencing a variable defined in the same action
- Example: Referencing a variable defined in another action
- Example: Referencing a secret
Example: Defining a variable using the Inputs property
The following example shows you how to define two variables, VAR1
and VAR2
, in an Inputs
section.
Actions: Build: Identifier: aws/build@v1 Inputs: Variables: - Name: VAR1 Value: "My variable 1" - Name: VAR2 Value: "My variable 2"
Example: Defining a variable using the Steps property
The following example shows you how to define a DATE
variable in
the Steps
section explicitly.
Actions: Build: Identifier: aws/build@v1 Configuration: Steps: - Run: DATE=$(date +%m-%d-%y)
Example: Exporting a variable using the Outputs property
The following example shows you how to define two variables,
REPOSITORY-URI
and TIMESTAMP
, and export them
using the Outputs
section.
Actions:
Build:
Identifier: aws/build@v1
Inputs:
Variables:
- Name: REPOSITORY-URI
Value: 111122223333.dkr.ecr.us-east-2.amazonaws.com/codecatalyst-ecs-image-repo
Configuration:
Steps:
- Run: TIMESTAMP=$(date +%m-%d-%y-%H-%m-%s)
Outputs:
Variables:
- REPOSITORY-URI
- TIMESTAMP
Example: Referencing a variable defined in the same action
The following example shows you how to specify a VAR1
variable in
MyBuildAction
, and then reference it in the same action using
$VAR1
.
Actions:
MyBuildAction:
Identifier: aws/build@v1
Inputs:
Variables:
- Name: VAR1
Value: my-value
Configuration:
Steps:
- Run: $VAR1
Example: Referencing a variable defined in another action
The following example shows you how to specify a TIMESTAMP
variable in BuildActionA
, export it using the Outputs
property, and then reference it in BuildActionB
using
${BuildActionA.TIMESTAMP}
.
Actions:
BuildActionA:
Identifier: aws/build@v1
Configuration:
Steps:
- Run: TIMESTAMP=$(date +%m-%d-%y-%H-%m-%s)
Outputs:
Variables:
- TIMESTAMP
BuildActionB:
Identifier: aws/build@v1
Configuration:
Steps:
- Run: docker build -t my-ecr-repo/image-repo:latest .
- Run: docker tag my-ecr-repo/image-repo:${BuildActionA.TIMESTAMP}
# Specifying just '$TIMESTAMP' here will not work
# because TIMESTAMP is not a variable
# in the BuildActionB action.
Example: Referencing a secret
The following example shows you how to reference a my-password
secret. The my-password
is the secret's key. This secret's key and
corresponding password value must be specified on the
Secrets page of the CodeCatalyst console prior to being used
in the workflow definition file. For more information, see Masking data using secrets.
Actions:
BuildActionA:
Identifier: aws/build@v1
Configuration:
Steps:
- Run: curl -u LiJuan:${Secrets.my-password} https://example.com