Closed lfarci closed 4 months ago
GitHub Actions provides a set of default environment variables that you can use in your workflows. These variables include information about the workflow run, the job, the runner, and the repository.
Here's an example of how to use these environment variables in a workflow:
name: Demo workflow
on: [push, pull_request]
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v2
- name: Print environment variables
run: |
echo "Runner OS: $RUNNER_OS"
echo "Repository: $GITHUB_REPOSITORY"
echo "Workflow: $GITHUB_WORKFLOW"
echo "Action: $GITHUB_ACTION"
echo "Event Name: $GITHUB_EVENT_NAME"
echo "Job: $GITHUB_JOB"
echo "Run ID: $GITHUB_RUN_ID"
echo "Run Number: $GITHUB_RUN_NUMBER"
echo "Actor: $GITHUB_ACTOR"
echo "SHA: $GITHUB_SHA"
echo "Ref: $GITHUB_REF"
echo "Head Ref: $GITHUB_HEAD_REF"
echo "Base Ref: $GITHUB_BASE_REF"
echo "Workspace: $GITHUB_WORKSPACE"
In this workflow, we have a job with two steps. The first step checks out the code, and the second step prints the values of several default environment variables.
The run
command is a multi-line command. Each line is a separate command that prints the name and value of an environment variable. The $
symbol is used to reference the value of an environment variable.
This workflow will run whenever a push or pull request event occurs. The output of the "Print environment variables" step can be viewed in the logs for the workflow run.
Default variables