解决 GitHub Actions 报错 The `set-output` command is deprecated 修复
排查 GitHub Actions 控制台大面积输出警告 The set-output command is deprecated and will be disabled soon,分析 GITHUB_OUTPUT 迁移。
问题现象
运行流水线时虽然通过,但每个 Job 均出现刺眼的黄色警告:
Warning: The `set-output` command is deprecated and will be disabled soon. Please upgrade to using Environment Files. For more information see: https://github.blog/changelog/2022-10-11-github-actions-deprecating-save-state-and-set-output-commands/
触发根因
- 旧式工作流使用了基于标准输出的命令语法
::set-output name=var::val,该语法存在安全注入风险已被官方废弃。
解决步骤
将旧写法迁移到新的 GITHUB_OUTPUT 环境变量文件
替换 YAML 中的 Shell 脚本命令:
# 旧写法:echo "::set-output name=app_version::1.2.3"
# 现代化新写法:
echo "app_version=1.2.3" >> "$GITHUB_OUTPUT"
对于多行字符串输出使用 EOF 语法
安全输出长文本:
{
echo "changelog<<EOF"
cat release_notes.txt
echo "EOF"
} >> "$GITHUB_OUTPUT"
验证确认
提交代码重新运行:
流水线纯净输出,所有黄色弃用警告彻底消失,步骤输出被下游 Job 完美接收。


