如何将bash命令的输出传递给Github Action参数 [英] How to pass the output of a bash command to Github Action parameter
问题描述
我有一个工作流程,在按下主控键后,我想创建一个发布并将其上载到资产.
我正在使用 actions/create-release @ v1
和 actions/upload-release-asset @ v1
.
I have a workflow where after a push to master I want to create a release and upload an asset to it.
I'm using actions/create-release@v1
and actions/upload-release-asset@v1
.
我想将bash命令的输出传递给动作参数.但是我发现"$(command)"的语法不起作用.
I would like to pass the outputs of a bash commands to the action parameters. However I found out the syntax of "$(command)" does not work.
如何将bash命令的输出传递给操作的参数.
How can I pass the output of a bash command to an action's parameter.
例如,我想做这样的事情:
For example I'd like to do something like this:
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.token }}
with:
tag_name: $(cat projectFile | grep -Po '(?<=Version>).*(?=</Version>)')
推荐答案
更新:由于安全原因,此答案无法在GitHub上使用,因为禁用了该语法.您应该使用环境文件.
UPDATE: This answer will not work as GitHub as disabled this syntax for security reasons. You should use environment files instead.
我将根据您的命令输出创建一个环境变量:
I would create an environment variable based of your command output:
- name: Retrieve version
run: |
echo ::set-env name=TAG_NAME::$(cat projectFile | grep -Po '(?<=Version>).*(?=</Version>)')
然后按以下方式访问它:
And then access it like the following:
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.token }}
with:
tag_name: ${{ env.TAG_NAME }}
这篇关于如何将bash命令的输出传递给Github Action参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!