Skip to main content

Expressions

You can evaluate expressions in workflows and actions.

About expressions

You can use expressions to programmatically set environment variables in workflow files and access contexts. An expression can be any combination of literal values, references to a context, or functions. You can combine literals, context references, and functions using operators. For more information about contexts, see Contexts reference.

Expressions are commonly used with the conditional if keyword in a workflow file to determine whether a step should run. When an if conditional is true, the step will run.

您需要使用特定语法指示 GitHub 对表达式求值,而不是将其视为字符串。

${{ <expression> }}

注意

The exception to this rule is when you are using expressions in an if clause, where, optionally, you can usually omit ${{ and }}. For more information about if conditionals, see GitHub Actions 的工作流语法.

警告

创建工作流和操作时,应始终考虑代码是否可能执行潜在攻击者的不受信任的输入。 某些上下文应被视为不受信任的输入,因为攻击者可能会插入自己的恶意内容。 有关详细信息,请参阅“GitHub Actions 的安全强化”。

Example setting an environment variable

env:
  MY_ENV_VAR: ${{ <expression> }}

Further reading

For technical reference information about expressions you can use in workflows and actions, see 对工作流和操作中的表达式求值.