Gitflow 分支模型的 Bitpucket 管道配置

问题描述 投票:0回答:1

我正在关注 Gitflow 分支模型的链接

在此图中,提交流程如下:

  1. 场景1:功能 -> 开发 -> 发布 -> 主控

  2. 场景 2: 修补程序 -> Master 和修补程序 -> Dev

  3. 场景 3: 发布 -> Master 和发布 -> Dev

我正在寻求实现 bitbucket 管道。大多数人推荐以下管道配置。

image: your-preferred-docker-image

pipelines:
  default:
    - step:
        name: Build and Test
        script:
          - echo "Build and test commands go here"

branches:
  master:
    - step:
        name: Deploy to Production
        script:
          - echo "Deployment to production goes here"

  develop:
    - step:
        name: Deploy to Staging
        script:
          - echo "Deployment to staging goes here"

  release/*:
    - step:
        name: Build and Test Release
        script:
          - echo "Build and test release branch"

它将为相应分支中的每次合并触发管道。我希望触发一次管道,它将等待手动触发来合并其他环境。

例如,

场景1: 如果有人将功能分支合并到 dev,它将触发 pipeline 并将其部署在 dev 中,并等待手动触发在release和master中部署相同的内容。

场景2: 如果有人将hotfix分支合并到master,它将触发管道并将其部署在master中,并等待手动触发将其部署在dev中,并且不会再次触发场景1。

场景3: 如果有人直接提交发布,它将触发管道并将其部署在发布中,并等待手动触发在master和dev中部署相同的内容,并且不会再次触发场景1和场景2。

非常感谢任何指导。预先感谢。

git cicd bitbucket-pipelines git-flow
1个回答
0
投票

要根据Gitflow分支模型实现Bitbucket管道,我们需要为每个场景定义具体的管道步骤,包括手动触发器。
对于 Bitbucket 管道,我们可以使用

manual
步骤 来控制何时进行部署:

image: your-preferred-docker-image

pipelines:
  default:
    - step:
        name: Build and Test
        script:
          - echo "Build and test commands go here"

  branches:
    master:
      - step:
          name: Deploy to Production
          trigger: manual
          script:
            - echo "Deployment to production goes here"

    develop:
      - step:
          name: Deploy to Staging
          trigger: manual
          script:
            - echo "Deployment to staging goes here"

    release/*:
      - step:
          name: Prepare Release
          script:
            - echo "Prepare release branch"
      - step:
          name: Deploy Release
          trigger: manual
          script:
            - echo "Deploy to release environment goes here"

    feature/*:
      - step:
          name: Integrate Feature
          script:
            - echo "Integrate feature into develop goes here"

该配置确保部署到

master
develop
release/*
分支需要手动触发,而不是在每次合并后自动部署。

  • 场景-1:合并功能分支进行开发将触发

    Integrate Feature
    步骤,但不会部署到登台。必须触发手动步骤才能部署到暂存。

  • 场景2:将修补程序分支合并到master将触发

    Deploy to Production
    步骤,但需要手动触发才能部署。部署到 master 后,必须触发手动步骤才能进行部署开发。

  • 场景-3:直接提交到发布分支将触发

    Prepare Release
    步骤,然后需要手动触发才能部署到发布环境。后续需要手动触发部署才能掌握和开发。


请注意,Bitbucket Pipelines 还支持可以手动触发的

custom
管道。如果您想对部署过程有更多控制,尤其是对于像您正在实施的复杂工作流程,这可能会很有用。

image: your-preferred-docker-image

pipelines:
  default:
    - step:
        name: Build and Test
        script:
          - echo "Build and test commands go here"

  branches:
    develop:
      - step:
          name: Integrate Feature
          script:
            - echo "Integrate feature into develop goes here"

    master:
      - step:
          name: Merge to Master
          script:
            - echo "Prepare production deployment"

  custom: # Custom pipelines definitions
    deploy-to-staging:
      - step:
          name: Manual Deploy to Staging
          script:
            - echo "Deployment to staging goes here"
            
    deploy-to-production:
      - step:
          name: Manual Deploy to Production
          script:
            - echo "Deployment to production goes here"

    deploy-release-to-envs:
      - step:
          name: Manual Deploy Release to Staging and Production
          script:
            - echo "Deploy release to both staging and production environments"

    deploy-hotfix-to-dev:
      - step:
          name: Manual Deploy Hotfix to Develop
          script:
            - echo "Deploy hotfix to develop environment"

每当您想要将

deploy-to-staging
分支部署到暂存环境时,您都可以手动触发
develop
自定义管道。
当您想要将
master
分支部署到生产环境时,您可以手动触发
deploy-to-production
自定义管道。

对于发布分支,准备好发布后,您可以手动触发

deploy-release-to-envs
部署到暂存和生产。
当您有修补程序需要部署到
develop
时,合并到
master
后,您可以手动触发
deploy-hotfix-to-dev

要手动触发自定义管道,您可以转到 Bitbucket 存储库的

Pipelines
部分,单击“
Run pipeline
”,选择分支,然后选择要运行的自定义管道。

此设置允许您的团队完全控制何时部署到不同的环境,而无需在每次推送或合并时自动触发管道。手动步骤只有在有人触发后才会运行,从而使您的团队有机会在部署之前检查更改。

© www.soinside.com 2019 - 2024. All rights reserved.