Member-only story

GitOps — Github Actions Workflow Contexts and Expressions

GitOps using Github Actions

Tony
4 min readApr 20, 2023

Workflow Contexts

In GitHub Actions, a context is a set of pre-defined objects or variables containing relevant information about the environment, events, or other data associated with a workflow run.

You can use contexts to access information about steps, workflow runs, jobs, and runner environments. Any time you want to access a context from within a workflow file, you need to use a syntax similar to ${{ <context> }}. For example:

name: Simple Contexts Example

on: push

jobs:
print-info:
runs-on: ubuntu-latest
steps:
- name: Set custom environment variable
run: echo "CUSTOM_VARIABLE=Hello, World!" >> $GITHUB_ENV

- name: Print commit author and custom environment variable
run: |
echo "Commit author: ${{ github.actor }}"
echo "Custom variable: ${{ env.CUSTOM_VARIABLE }}"

In this example, the github.actor context provides the username of the person who triggered the push event, and the env.CUSTOM_VARIABLE context refers to the custom environment variable set in the previous step. The workflow prints both of these values to the console.

--

--

Tony
Tony

Responses (1)