Rah*_*mar 5 yaml github sonarqube github-actions
我已经在 GitHub Actions 上工作了一段时间了,我们已经制定了指定的工作流程。工作流程是用 yaml 编写的。
我试图if为github.ref和 yaml 的块设置一些条件,该块在运行时被跳过。这意味着 - 如果针对 X 分支提出拉取请求 - 该代码块应该运行。
像这样的东西:
- name: Branch name check - Running only for DEV branch..
if: ${{contains(github.ref, 'DEV*')}}
uses: mathrix-education/sonar-scanner@master
with:
version: 4.2.0.1873 # required
typescript: false
scan: true
Run Code Online (Sandbox Code Playgroud)
谁能帮我解决这个问题吗?
Neb*_*tic 10
我们在构建 github 工作流程时遇到了类似的事情。我们的工作条件:
经过一番研究,我们得出以下结论。我发现 Github Actions 非常灵活,有很多 Gitlab 和 Bitbucket 没有的选项。但这也是缺点,有时会使其理解起来更加复杂。
---
name: my-workflow
on:
push:
branches:
- develop
pull_request:
branches:
- develop
- main
types:
- closed
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: checkout repo
uses: actions/checkout@v1
- name: step 1
if: github.ref == 'refs/heads/develop' || github.event.pull_request.base.ref == 'develop'
run: echo "Hello develop"
- name: step 2
if: github.event.pull_request.base.ref == 'master'
run: echo "Hello master"
Run Code Online (Sandbox Code Playgroud)
我建议不要在分支上过于频繁地使用 if 语句。这会导致不同分支的部署之间不一致。对于某些用例,您可能更适合使用github 环境(仅限企业)。例如,如果您需要为不同的分支设置不同的环境变量或秘密。下面是一个简单的示例,您可以有两个 github 环境(开发环境和主环境),两者都包含不同的 MY_SECRET 秘密值。
name: my-workflow
on:
push:
branches:
- develop
- main
jobs:
deploy:
runs-on: ubuntu-latest
name: Do something
steps:
- run: echo "Example using environments corresponding branch names"
environment: ${{ github.ref == 'refs/heads/main' && 'main' || github.ref == 'refs/heads/develop' && 'develop' }}
env:
MY_SECRET: ${{ secrets.MY_SECRET }}
Run Code Online (Sandbox Code Playgroud)
使用以下命令检查拉取请求的基础:
if: ${{contains(github.base_ref, 'DEV')}}
github.ref将包含类似refs/pull/1/merge拉取请求的内容。
| 归档时间: |
|
| 查看次数: |
12064 次 |
| 最近记录: |