简体   繁体   English

GitHub Actions restrict job with tag validation using if condition or github 参考

[英]GitHub Actions restrict job with tag validation using if condition or github ref

I have an application code which runs the maven builds we created snapshots and then create a tag created once the snapshot build is successful, and then we use the tag created in the snapshot build and then run the build using the tag for release using the GitHub actions workflows.我有一个运行 maven 构建的应用程序代码,我们创建了快照,然后在快照构建成功后创建一个标签,然后我们使用在快照构建中创建的标签,然后使用标签运行构建以使用 GitHub 发布动作工作流程。 now I'm trying to run the release of the build workflow job only if the tag as matching and if the tag, not matches, skip the jobs or fails the jobs, let's say the tag will be created in the snapshot build and will use tag format as "<appname>-<app_build_type>-<github-actions-run_number>-<env>-origin/<branch>" and the actual tag looks like "java-maven-44-dev-origin/develop" I was trying the below 2 methods workflows, but it is not at all working 1st Method is:现在我正在尝试仅在标签匹配时运行构建工作流作业的发布,如果标签不匹配,则跳过作业或作业失败,假设标签将在快照构建中创建并将使用标签格式为"<appname>-<app_build_type>-<github-actions-run_number>-<env>-origin/<branch>" ,实际标签看起来像"java-maven-44-dev-origin/develop"我正在尝试以下 2 种方法工作流程,但它根本不起作用第一种方法是:

name: maven-release

on:
  workflow_dispatch:

jobs:
  checkout_code:
    runs-on: [ubuntu-latest]
    steps:
      - name: Checkout
        uses: actions/checkout@v3
        with:
          fetch-depth: 0

  maven_build:
    runs-on: [ubuntu-latest]
    if: ${{ github.ref == 'refs/tags/*-origin/develop' }}
    needs: checkout_code
    steps:
      - name: Run maven build
        run: |
          mvn clean install

2nd Method is:第二种方法是:

name: maven-release

on:
  workflow_dispatch:

jobs:
  checkout_code:
    runs-on: [ubuntu-latest]
    steps:
      - name: Checkout
        uses: actions/checkout@v3
        with:
          fetch-depth: 0

  maven_build:
    runs-on: [ubuntu-latest]
    if: contains(github.ref, 'refs/tags/*-origin/develop')
    needs: checkout_code
    steps:
      - name: Run maven build
        run: |
          mvn clean install

I want to skip/fail the at job level only and no in run command, if anyone knows any solution to this or anyone can provide some suggestions on how to achieve this我只想跳过/失败 at job level 而不是 in run 命令,如果有人知道这个的任何解决方案或者任何人都可以提供一些关于如何实现这个的建议

Its it's possible for your use case, you could trigger your workflow on push and then apply your filter to the branch or tag它可能适用于您的用例,您可以在推送时触发您的工作流程,然后将您的过滤器应用于分支或标签

name: maven-release

on:
  workflow_dispatch:
  push:
    tags:
      - '*-origin/develop'

jobs:
  checkout_code:
    runs-on: [ubuntu-latest]
    steps:
      - name: Checkout
        uses: actions/checkout@v3
        with:
          fetch-depth: 0

  maven_build:
    runs-on: [ubuntu-latest]
    if: ${{ github.ref == 'refs/tags/*-origin/develop' }}
    needs: checkout_code
    steps:
      - name: Run maven build
        run: |
          mvn clean install

The Github filter pattern cheat sheet Github 过滤器模式备忘单

For the workflows for which each task needs to be executed only on a particular tag, then we can make use of below snipped对于每个任务只需要在特定标签上执行的工作流程,那么我们可以利用下面的片段

name: maven_build
on:
  workflow_dispatch:
jobs:
  checkout:
    runs-on: [ubuntu-latest]
    steps:
      - name: Checkout
        uses: actions/checkout@v3
        with:
          fetch-depth: 0
  maven_build:
    runs-on: [ubuntu-latest]
    if: startsWith(github.ref, 'refs/tags/') && !contains(github.ref')
    needs: checkout
    steps:
      - name: Run maven build command
        run: |
          mvn clean install

The above snippet will run only when the checkout branch matches a tag上面的代码片段只会在结帐分支匹配标签时运行

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 github 操作将工件 (Maven) 部署到 Github 包 - How to deploy an artifact (Maven) to Github package using github actions 使用github作为Maven存储库校验和验证失败 - using github as maven repository Checksum validation failed 尝试使用 github 操作(maven)部署到 github 包时出现错误代码 400 - Error Code 400 when trying to (maven) deploy to github packages using github actions 如何从 GitHub 包下载最新的 jar 文件并使用 Maven GitHub 操作部署到云集线器? - How to download the latest jar file from GitHub packages and deploy to cloud hub using Maven GitHub actions? Maven 从 Github 操作中释放 - Maven release from Github Actions 自动发布 JavaDoc:使用 GitHub 操作 - Publish automatically JavaDoc: with GitHub Actions 在将构建的 jar 发布到 github 时,是否有使用 github 操作上传的功能? - Is there a function to upload with github actions on a release the builded jar to github? 如何使用 GitHub 操作安装由 GitHub 包托管的包 - How to install a package hosted by GitHub Packages with GitHub Actions 如何在 Github Actions 工作流上从 Github 包访问 Maven 依赖项? - How to access Maven dependency from Github Packages on a Github Actions workflow? 为另一个目录中的“使用”运行 github 操作 - Running github actions for `uses` in another directory
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM