GitHub Actions Certification
Custom Actions
Implement workflow commands within an Step
GitHub Actions workflow commands let you interact with the runner environment, annotate logs, set variables, mask secrets, and generate summaries by issuing specially formatted echo
statements. These commands work in any workflow step, not just within the Actions Toolkit:
echo "::command parameter1={data},parameter2={data}::{message}"
Note
You can find a complete list of commands and parameters in the Workflow Commands for GitHub Actions documentation.
For full details, see the official GitHub Actions workflow commands documentation.
Demo Repository: ga-workflow-step-command-demo
In this demo, we use a repository named ga-workflow-step-command-demo
(under the KodeKloud training org). It contains a single workflow, Exploring Workflow Commands, which runs on ubuntu-latest
and triggers on push
(main branch) or via workflow_dispatch
. Each step illustrates a different command:
name: Exploring Workflow Commands
on:
push:
branches: [ main ]
workflow_dispatch:
jobs:
commands_job:
runs-on: ubuntu-latest
steps:
- name: Set environment variable
run: echo "COMPANY_VAR=KodeKloud" >> $GITHUB_ENV
- name: Use environment variable
run: echo "Hello, $COMPANY_VAR!"
- name: Group log lines
run: |
echo "::group::Custom Log Group"
echo "This is line 1"
echo "This is line 2"
echo "::endgroup::"
- name: Mask a value
env:
key: p@$Sw0Rd
run: |
echo "Unmasked key = $key"
echo "::add-mask::$key"
echo "Masked key = $key"
- name: Create a warning message
run: echo "::warning::This is a warning message."
- name: Create an error annotation
run: echo "::error file=index.js,line=1::Missing semicolon"
- name: Set a debug message
run: echo "::debug::This is a debug message."
- name: Create a notice annotation
run: echo "::notice file=src/index.js,line=42::Custom notice message"
- name: Set an output value
id: my_output
run: echo "myOutput=007" >> "$GITHUB_OUTPUT"
- name: Show the output value
run: echo "My output value is ${{ steps.my_output.outputs.myOutput }}"
- name: Job Summary
run: |
echo "### Awesome Job Summary :rocket:" >> $GITHUB_STEP_SUMMARY
echo "## Used Workflow Commands" >> $GITHUB_STEP_SUMMARY
echo "- Debug" >> $GITHUB_STEP_SUMMARY
echo "- Mask" >> $GITHUB_STEP_SUMMARY
echo "- Output" >> $GITHUB_STEP_SUMMARY
echo "- Variable" >> $GITHUB_STEP_SUMMARY
echo "- Annotations" >> $GITHUB_STEP_SUMMARY
echo "- Groups" >> $GITHUB_STEP_SUMMARY
echo "Secret Key from previous step: $key" >> $GITHUB_STEP_SUMMARY
echo "Output from previous step: ${{ steps.my_output.outputs.myOutput }}" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
Workflow Commands at a Glance
Command | Use Case | Syntax Example |
---|---|---|
Set environment var | Share data across steps | echo "VAR=value" >> $GITHUB_ENV |
Group logs | Collapse/expand related log lines | ::group::Title ... ::endgroup:: |
Mask secret | Hide sensitive values | ::add-mask::$SECRET |
Create warning/error | Annotate logs with issues | ::warning::Message / ::error file=app.js,line=5 |
Set output | Pass data to subsequent steps | echo "key=value" >> $GITHUB_OUTPUT |
Job summary | Append to end-of-job summary file | echo "#### Summary" >> $GITHUB_STEP_SUMMARY |
Running the Workflow
Trigger the Exploring Workflow Commands workflow manually or push to the main
branch. Since it doesn’t call external services, it completes in seconds. After a successful run, you’ll see annotations for warnings, errors, and notices:
Clicking an annotation opens the specified file and line number. Below the annotations, you’ll find the custom job summary:
You can also inspect live logs to see each step:
Warning
Be cautious when masking secrets. Once added, they cannot be retrieved in plain text within the runner.
Combined, these workflow commands help you produce clear, well-structured logs and summaries in your CI/CD pipelines.
Links and References
Watch Video
Watch video content