【问题标题】:prevent the bitbucket pipline from tirggering when bitbucket-pipelines.yml is updated防止在 bitbucket-pipelines.yml 更新时触发 bitbucket 管道
【发布时间】:2021-06-13 08:28:51
【问题描述】:

我是 bitbuckt 管道的新手。在我的节点项目中,我在管道中添加了bitbucket-pipelines.yml,我有一个步骤来构建容器并将其推送到 ECR,还有一个步骤来部署。

现在每次我对 bitbucket-pipelines.yml 进行更改时,它都会构建一个新图像并将其推送到 ECR 并进行部署。

当我对 bitbucket-pipelines.yml 进行更改时,我不知道要触发什么流水线。我只希望在我对应用程序进行更改时触发管道。我是不是把项目设置错了?

我的项目结构。

.
├── bitbucket-pipelines.yml
├── Dockerfile
├── index.js
├── node_modules
├── package.json
├── package-lock.json
└── README.md

【问题讨论】:

  • 嗨,你能分享你的 bitbucket 管道设置吗,可能你在顶部使用 default: 关键字。您可以将其更改为标签,以便您可以标记要触发部署的提交,或尝试自定义关键字以手动运行管道。

标签: bitbucket bitbucket-pipelines


【解决方案1】:

有几种可能的选择:

1.将 [skip ci] 添加到您的 git 提交消息中

每当您自行更改 bitbucket-pipelines.yml 时,请在您的 Git 提交消息中的某处添加“[skip ci]”(不带引号)。当您推送到 Bitbucket 远程时,这将阻止管道运行。

优点:

  • 简单易行。

缺点:

  • 您必须记住手动编写"[skip ci]" 文本。这很容易忘记,或者新的团队成员可能不知道。

2.使用 Git Hook 自动修改您的 git 提交消息

编写一个 Git Hook 脚本,它会自动将“[skip ci]”文本插入到 Git 提交消息中。该脚本必须执行以下操作:

  1. 本地提交后,检查最新提交到see which files were changed。使用类似git diff --name-only HEAD~0 HEAD~1
  2. 如果 bitbucket-pipelines.yml 是唯一更改的文件,请修改提交以将 "[skip ci]" 插入到提交消息中。

更多关于 Git Hooks 的信息:

优点:

  • 它是全自动的。无需手动标记您的提交消息。

缺点:

3.让bitbucket-pipelines.yml 检查文件更改

yml 构建脚本中添加一个部分,以检查在最新提交中更改了哪个文件。

yml 中的脚本必须执行以下操作:

  1. 检查最新提交以查看更改了哪些文件。使用类似git diff --name-only HEAD~0 HEAD~1
  2. 如果 bitbucket-pipelines.yml 是唯一更改的文件,请立即使用 exit 0 语句中止 CI 构建。

优点:

  • 它是全自动的。无需手动标记您的提交消息。
  • 无需编写 Git Hook 脚本。

缺点:

  • CI 构建的 Docker 映像需要 1-5 分钟才能加载,然后会自行中止。这有点低效,而且会消耗一些构建时间。
  • 因为 CI 构建仍会运行几分钟,它会污染您的 CI 构建历史,因为构建运行没有执行任何操作。

4.使用带有“changesets”和“includePaths”的条件步骤

使用includePaths 定义changesets 以仅在修改后的文件之一与includePaths 中的表达式匹配时执行步骤。

pipelines:
  default:
    - step:
        name: build-frontend-artifact
        condition:
          changesets:
            includePaths:
              # only xml files directly under resources directory
              - "src/main/resources/*.xml"
              # any changes in frontend directory
              - "src/site/**"
        script:
          - echo "Building frontend artifact"

来源和更多信息在这里:https://bitbucket.org/blog/conditional-steps-and-improvements-to-logs-in-bitbucket-pipelines

【讨论】:

    猜你喜欢
    • 2022-06-27
    • 1970-01-01
    • 2022-06-11
    • 2021-10-14
    • 2018-06-12
    • 2021-12-10
    • 1970-01-01
    • 1970-01-01
    • 2017-04-07
    相关资源
    最近更新 更多