github动作开始工作流程,请求多个分支多环境
我正在尝试使用以下条件开始github操作工作流程作业,每个条件都会启动一个单独的作业:
- 如果有新的拉力请求将DEV分支机构 -
- 如果将代码合并到DEV分支机构 - 将基础结构与Dev Environal部署到DEV环境 - 将基础结构部署到UAT环境
- 如果有新的拉力请求到主分支机构 -
- 如果将代码合并到主要分支机构,则将
on:
push:
branches:
- dev
- main
pull_request:
types: [opened, reopened]
branches:
- dev
- main
workflow_dispatch:
jobs:
DeployDev:
name: Deploy to dev
if: ${{github.ref == 'refs/heads/dev' && github.event_name == 'pull_request'}}
runs-on: ubuntu-latest
environment: dev
more steps follows ......
基础架构部署到分期环境, -在其他匹配条件下,将基础架构部署到生产环境(要运行的单独工作),我正在使用
部署:部署:
if: ${{github.ref == 'refs/heads/dev' && github.event_name == 'push'}}
部署:
if: ${{github.ref == 'refs/heads/main' && github.event_name == 'pull_request'}}
decloveprod:
${{github.ref == 'refs/heads/main' && github.event_name == 'push'}}
合并代码时似乎运行正常,但是当创建拉动请求时没有运行。
有人可以指向我我在做什么错吗?我尝试删除行类型:[打开,重新打开]
,但没有任何区别。
I am trying to start Github actions workflow jobs with the following conditions, with each condition initiating a separate job:
- If there is a new pull request to dev branch - deploy infrastructure to dev environment
- If the code is merged to dev branch - deploy infrastructure to uat environment
- If there is a new pull request to main branch - deploy infrastructure to staging environment
- If the code is merged to main branch - deploy infrastructure to production environment
on:
push:
branches:
- dev
- main
pull_request:
types: [opened, reopened]
branches:
- dev
- main
workflow_dispatch:
jobs:
DeployDev:
name: Deploy to dev
if: ${{github.ref == 'refs/heads/dev' && github.event_name == 'pull_request'}}
runs-on: ubuntu-latest
environment: dev
more steps follows ......
similarly for other matching conditions (separate jobs to run), I am using
DeployUat:
if: ${{github.ref == 'refs/heads/dev' && github.event_name == 'push'}}
DeployStaging:
if: ${{github.ref == 'refs/heads/main' && github.event_name == 'pull_request'}}
DeployProd:
${{github.ref == 'refs/heads/main' && github.event_name == 'push'}}
Workflow jobs seems to be running ok when code is merged, but not when a pull request is created.
Can someone point me what am I doing wrong ? I tried removing the line types: [opened, reopened]
, but does not makes any difference.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想我找到了答案。
而不是
如果:$ github.ref =='refs/heads/dev'&& github.event_name =='pull_request'
应该是
如果:$ github.event.pull_request.base.ref =='dev'&& github.event_name =='pull_request'
I think I found the answer.
Instead of
if: $github.ref == 'refs/heads/dev' && github.event_name == 'pull_request'
It should be
if: $github.event.pull_request.base.ref == 'dev' && github.event_name == 'pull_request'