如何 运行 基于标签名称的作业

How to run a job based on a tag-name

我有以下情况:

name: Build Image

on:
  push:
  pull_request:
  workflow_dispatch:
    

jobs:

  build-image: (This should be only if the tag contains "azure")
    name: Build Image Job
    runs-on: [ self-hosted ]

    steps:
    - uses: actions/checkout@v2

    - name: Run Build Step
      run: |
        ANSIBLE_VERSION=$(cat VERSION)
        docker images

jobs:

  build-image: (This will be for everything else)
    name: Build Image Job
    runs-on: [ self-hosted ]

    steps:
    - uses: actions/checkout@v2

    - name: Run Build Step
      run: |
        ANSIBLE_VERSION=$(cat VERSION)
        docker images

如何实现?你如何引用作业中的标签? 您如何处理变量并从中得出 if 规则?

您可以在 on 配置中使用正则表达式来触发基于标签名称的工作流。例如:

on:
  push:
    tags:
      - '*azure*'

在作业或步骤级别,您可以使用 contains() 表达式:

jobs:
  build-for-azure-tag:
    name: build-for-azure-tag
    runs-on: ubuntu-latest
    if: github.ref_type == 'tag' && contains(github.ref_name, 'azure')