在 Github Actions 中获取当前推送的标签 [英] Get the current pushed tag in Github Actions
问题描述
有没有办法访问在 Github Action 中推送的当前标签?在 CircleCI 中,您可以使用 $CIRCLE_TAG
变量访问此值.
Is there a way to access the current tag that has been pushed in a Github Action? In CircleCI you can access this value with the $CIRCLE_TAG
variable.
我的工作流程 yaml 被这样的标签触发:
My Workflow yaml is being triggered by a tag like so:
on:
push:
tags:
- 'v*.*.*'
我想稍后在工作流程中使用该版本号作为文件路径.
And I want to use that version number as a file path later on in the workflow.
推荐答案
据我所知没有标签变量.但是,它可以从包含签出 ref 的 GITHUB_REF
中提取,例如refs/tags/v1.2.3
As far as I know there is no tag variable. However, it can be extracted from GITHUB_REF
which contains the checked out ref, e.g. refs/tags/v1.2.3
试试这个工作流程.它使用提取的版本创建一个新的环境变量,您可以在以后的步骤中使用它.
Try this workflow. It creates a new environment variable with the extracted version that you can use in later steps.
on:
push:
tags:
- 'v*.*.*'
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set env
run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
- name: Test
run: |
echo $RELEASE_VERSION
echo ${{ env.RELEASE_VERSION }}
或者,使用 set-output
:
on:
push:
tags:
- 'v*.*.*'
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set output
id: vars
run: echo ::set-output name=tag::${GITHUB_REF#refs/*/}
- name: Check output
env:
RELEASE_VERSION: ${{ steps.vars.outputs.tag }}
run: |
echo $RELEASE_VERSION
echo ${{ steps.vars.outputs.tag }}
这篇关于在 Github Actions 中获取当前推送的标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!