在Github Actions中获取当前的推送标签 [英] Get the current pushed tag in Github Actions

查看:530
本文介绍了在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.

我已将基于所选答案的最终解决方案作为下面的另一个答案: https://stackoverflow.com/a/58195087/756514

I have included my final solution based on the chosen answer as another answer below: https://stackoverflow.com/a/58195087/756514

推荐答案

据我所知没有标签变量。但是,它可以从 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@v1
      - name: Set env
        run: echo ::set-env name=RELEASE_VERSION::${GITHUB_REF#refs/*/}
      - 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@v1
      - 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆