【发布时间】:2022-01-24 22:01:17
【问题描述】:
我在 GitHub 操作中从我的存储库中获取 feature/* 分支列表,使用:
echo ::set-output name=branches::$( git branch -r | grep -i "feature/" | sed -e "s/.*origin\///" | tr "\n" " " )
但是,这个列表是字符串输出,我需要它在一个字符串数组中,这样我就可以使用它来使用矩阵策略调用另一个工作流。
我尝试了多种策略,包括:
- 将表达式包装在
()中会导致语法错误(“意外令牌:(”) - 使用导致空字符串的环境变量在
()中包含或不包含表达式 - 使用局部变量会根据我的分配方式产生不同的结果。在我的开发环境中,我有 2 个功能分支(feature/quality-3 和 feature/test-feature)
使用:
branches=($( git branch -r | grep -i "feature/" | sed -e "s/.*origin\///" | tr "\n" " " ))
与:
echo ::set-output name=branches::${branches[@]} # also ${branches[*]}
给出两个值的错误:“值的类型意外'feature/quality-3 feature/test_feature',预期类型:序列。”
与:
echo ::set-output name=branches::${branches} # or $branches
给出 1 个值的错误:“值 'feature/quality-3' 的意外类型,预期类型:序列。”
【问题讨论】:
标签: ubuntu yaml github-actions