跳到主要内容

Using Script Commands

Applicable scenarios: When you need to execute shell commands, call scripts in the repository, set environment variables, or write output parameters in a step.

Prerequisites

  • runs-on has been configured and you are familiar with the pre-installed tools of the Runner.
  • If executing a script in the repository, you need to check out the code first.

Quick Example

jobs:
build:
runs-on: [ubuntu-latest, x64, small]
steps:
- uses: checkout
- name: Run build script
run: bash ./scripts/build.sh

Configuration Description

Execute Scripts in the Repository

Execute existing script files in the repository:

steps:
- uses: checkout
- name: Run build script
run: bash ./scripts/build.sh

Note: The script file may not have execution permissions. It is recommended to use bash script.sh or first run chmod +x script.sh.

Set Execution Permissions

steps:
- uses: checkout
- run: chmod +x ./scripts/build.sh
- run: ./scripts/build.sh

Write Step Output

Use the ATOMGIT_OUTPUT environment variable to write step output parameters:

steps:
- id: version
run: echo "version=1.0.0" >> "$ATOMGIT_OUTPUT"
- name: Use output
run: echo "${{ steps.version.outputs.version }}"

Set Environment Variables

Use the ATOMGIT_ENV environment variable to set environment variables visible to subsequent steps:

steps:
- name: Set env
run: echo "APP_VERSION=1.0.0" >> "$ATOMGIT_ENV"
- name: Use env
run: echo "version=$APP_VERSION"

Add PATH

Use ATOMGIT_PATH to add a path to the system PATH:

steps:
- name: Add custom tool to PATH
run: echo "/opt/custom-tools" >> "$ATOMGIT_PATH"
- name: Use custom tool
run: custom-tool --version

Masked Commands

Use ::add-mask:: to mask sensitive information in logs:

steps:
- name: Mask secret
run: |
echo "::add-mask::$MY_SECRET"
echo "The secret value is $MY_SECRET"

The value of $MY_SECRET in the log will be displayed as ***.

Multi-line Output

Use a delimiter when writing multi-line values to output or environment variables:

steps:
- id: multiline
run: |
EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64)
echo "content<<$EOF" >> "$ATOMGIT_OUTPUT"
echo "line1" >> "$ATOMGIT_OUTPUT"
echo "line2" >> "$ATOMGIT_OUTPUT"
echo "$EOF" >> "$ATOMGIT_OUTPUT"