将步骤的输出设置为数组
Set output of step as array
我在 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',预期类型:序列。”
我在 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',预期类型:序列。”