[英]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.