mcpField
B
bitbucket-workflow

bitbucket-workflow

github.com/mindrally开发287763 次安装3 周前更新
代码仓库

关于 bitbucket-workflow

为使用 Bitbucket 管理代码审查、CI/CD、Jira 跟踪和 Atlassian 集成的团队提供工作流指导,内容涵盖仓库控制与部署实践。

主要功能

  1. 01Pull request 与审查实践
  2. 02配置 Bitbucket Pipelines
  3. 03Jira 问题与提交工作流
  4. 04分支权限与合并检查
  5. 05部署与仓库安全

适用场景

  1. 01统一 Pull request 审查流程
  2. 02设置 CI/CD 流水线
  3. 03将代码变更关联到 Jira 问题
  4. 04控制仓库合并与部署

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/mindrally/skills --skill bitbucket-workflow

安装后在 Claude Code 中输入/bitbucket-workflow确认已加载。

详细介绍

Bitbucket 工作流最佳实践

你是 Bitbucket 工作流方面的专家,精通拉取请求、Bitbucket Pipelines、Jira 集成和 Atlassian 生态系统最佳实践。

核心原则

  • 所有代码变更都通过拉取请求进行,并采用规范的审查流程
  • 使用 bitbucket-pipelines.yml 通过 Bitbucket Pipelines 实施 CI/CD
  • 利用 Jira 集成,实现无缝的问题跟踪
  • 遵循 Gitflow 等分支模型,规范开发流程
  • 通过分支权限和访问控制维护安全性

拉取请求最佳实践

创建有效的拉取请求
  1. 让 PR 聚焦且便于审查

    • 每个 PR 只包含一项功能或修复
    • 在描述中提供背景信息
  2. PR 标题规范

    • 引用 Jira 问题:PROJ-123: Add user authentication
    • 使用约定格式:feat: implement login page
  3. PR 描述模板

    ## Summary
    Brief description of changes and motivation.
    
    ## Jira Issue
    [PROJ-123](https://your-org.atlassian.net/browse/PROJ-123)
    
    ## Changes
    - List of specific changes made
    
    ## Testing
    - How the changes were tested
    - Manual testing steps
    
    ## Checklist
    - [ ] Tests added/updated
    - [ ] Documentation updated
    - [ ] Pipeline passes
    
在 Bitbucket 中进行代码审查
  1. 添加审查者 - 选择合适的团队成员
  2. 使用任务 - 为可执行的反馈创建任务
  3. 批准或请求更改 - 使用清晰的审批流程
  4. 解决讨论 - 合并前处理所有反馈
合并策略
  • 合并提交:保留完整的分支历史
  • 压缩:将多个提交合并为一个提交
  • 快进合并:尽可能保持线性历史

Bitbucket Pipelines

基本流水线配置
image: node:20

definitions:
  caches:
    npm: ~/.npm

  steps:
    - step: &build-step
        name: Build
        caches:
          - npm
        script:
          - npm ci
          - npm run build
        artifacts:
          - dist/**

    - step: &test-step
        name: Test
        caches:
          - npm
        script:
          - npm ci
          - npm test

pipelines:
  default:
    - step: *build-step
    - step: *test-step

  branches:
    main:
      - step: *build-step
      - step: *test-step
      - step:
          name: Deploy to Production
          deployment: production
          trigger: manual
          script:
            - pipe: atlassian/aws-s3-deploy:1.1.0
              variables:
                AWS_ACCESS_KEY_ID: $AWS_ACCESS_KEY_ID
                AWS_SECRET_ACCESS_KEY: $AWS_SECRET_ACCESS_KEY
                AWS_DEFAULT_REGION: 'us-east-1'
                S3_BUCKET: 'my-bucket'
                LOCAL_PATH: 'dist'

    develop:
      - step: *build-step
      - step: *test-step
      - step:
          name: Deploy to Staging
          deployment: staging
          script:
            - ./deploy.sh staging
流水线功能
并行步骤
pipelines:
  default:
    - parallel:
        - step:
            name: Unit Tests
            script:
              - npm test:unit
        - step:
            name: Integration Tests
            script:
              - npm test:integration
        - step:
            name: Lint
            script:
              - npm run lint
条件步骤
pipelines:
  pull-requests:
    '**':
      - step:
          name: Build and Test
          script:
            - npm ci
            - npm test
          condition:
            changesets:
              includePaths:
                - "src/**"
                - "package.json"
自定义 Pipe
pipelines:
  default:
    - step:
        name: Deploy
        script:
          - pipe: atlassian/aws-ecs-deploy:1.6.0
            variables:
              AWS_ACCESS_KEY_ID: $AWS_ACCESS_KEY_ID
              AWS_SECRET_ACCESS_KEY: $AWS_SECRET_ACCESS_KEY
              AWS_DEFAULT_REGION: 'us-east-1'
              CLUSTER_NAME: 'my-cluster'
              SERVICE_NAME: 'my-service'
              TASK_DEFINITION: 'task-definition.json'
测试服务
definitions:
  services:
    postgres:
      image: postgres:15
      variables:
        POSTGRES_DB: test_db
        POSTGRES_USER: test_user
        POSTGRES_PASSWORD: test_pass
    redis:
      image: redis:7

pipelines:
  default:
    - step:
        name: Integration Tests
        services:
          - postgres
          - redis
        script:
          - npm ci
          - npm run test:integration
缓存
definitions:
  caches:
    npm: ~/.npm
    pip: ~/.cache/pip
    gradle: ~/.gradle/caches

pipelines:
  default:
    - step:
        caches:
          - npm
        script:
          - npm ci
          - npm run build

Jira 集成

Smart Commits

启用 Smart Commits,以便通过提交消息更新 Jira 问题:

PROJ-123 #comment Fixed the login redirect issue
PROJ-123 #time 2h 30m
PROJ-123 #done
分支命名

在分支名称中包含 Jira 问题键:

  • feature/PROJ-123-user-authentication
  • bugfix/PROJ-456-fix-login-redirect

这会自动将分支关联到问题。

自动化规则

设置 Jira 自动化:

  • 创建分支时,将问题移至“In Progress”
  • 打开 PR 时,将问题移至“In Review”
  • 合并 PR 时,将问题移至“Done”

分支模型

在 Bitbucket 中使用 Gitflow
pipelines:
  branches:
    main:
      - step:
          name: Deploy Production
          deployment: production
          script:
            - ./deploy.sh production

    develop:
      - step:
          name: Deploy Staging
          deployment: staging
          script:
            - ./deploy.sh staging

    'release/*':
      - step:
          name: Release Build
          script:
            - npm run build:release

    'feature/*':
      - step:
          name: Feature Build and Test
          script:
            - npm ci
            - npm test

    'hotfix/*':
      - step:
          name: Hotfix Build
          script:
            - npm ci
            - npm test
分支权限

在 Repository settings > Branch permissions 中配置:

主分支:

  • 禁止直接推送
  • 要求使用拉取请求
  • 至少需要 1 个批准
  • 要求构建通过
  • 要求解决所有任务

开发分支:

  • 要求使用拉取请求
  • 至少需要 1 个批准
  • 要求构建通过

仓库管理

默认审查者

设置默认审查者,确保代码审查流程一致:

  • 将团队负责人设为默认审查者
  • 使用类似 CODEOWNERS 的模式
合并检查

启用合并检查:

  • 最低批准数
  • 无未解决任务
  • 构建通过
  • 无更改请求
访问级别
  • 管理员:完全控制
  • 写入:推送和合并
  • 读取:克隆和查看

安全最佳实践

仓库变量

在 Repository settings > Pipelines > Variables 中配置安全变量:

# Reference in pipeline
script:
  - echo "Deploying with token"
  - ./deploy.sh --token=$DEPLOY_TOKEN

变量选项:

  • 安全:在日志中屏蔽
  • 部署时必需
IP 允许列表

限制流水线只能从特定 IP 范围访问部署环境。

访问令牌

使用仓库或项目访问令牌,而非个人令牌:

  • 限定为特定仓库
  • 更易轮换
  • 审计跟踪更完善

部署环境

环境配置
pipelines:
  branches:
    main:
      - step:
          name: Deploy to Production
          deployment: production
          script:
            - ./deploy.sh

在 Repository settings > Deployments 中配置环境:

  • 为每个环境设置环境变量
  • 配置部署权限
  • 查看部署历史记录
部署权限
  • 要求特定用户批准生产部署
  • 设置部署时间窗口
  • 启用部署冻结期

Atlassian 生态系统集成

Confluence 集成
  • 将仓库关联到 Confluence 空间
  • 嵌入代码片段
  • 根据提交自动更新文档
Trello 集成
  • 将卡片关联到提交
  • 根据 PR 事件自动移动卡片
Opsgenie 集成
  • 在流水线失败时触发警报
  • 部署问题的值班通知

最佳实践总结

  1. 使用带有 Jira 键的描述性分支名称
  2. 为主分支配置分支权限
  3. 通过适当的阶段实施全面的流水线
  4. 对常见任务使用 pipes(AWS、Docker 等)
  5. 启用 smart commits 以更新 Jira
  6. 设置具有适当权限的部署环境
  7. 使用仓库变量存储机密
  8. 配置合并检查作为质量门禁
  9. 利用 Atlassian 集成实现无缝工作流

评论

支持 Markdown