我是位桶管道的新手。我已经添加到我的节点项目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
有几种可能的选择:
1. Add [skip ci]
到你的 git 提交消息
每当你改变bitbucket-pipelines.yml
单独添加“[跳过ci]”(不带引号)在 Git 提交消息中的某处。当您推送到 Bitbucket 远程时,这将阻止管道运行。
来源和更多信息:
- https://confluence.atlassian.com/bbkb/how-to-skip-triggering-a-pipeline-build-using-skip-ci-label-1207188270.html https://confluence.atlassian.com/bbkb/how-to-skip-triggering-a-pipeline-build-using-skip-ci-label-1207188270.html
- https://support.atlassian.com/bitbucket-cloud/docs/pipeline-start-conditions/ https://support.atlassian.com/bitbucket-cloud/docs/pipeline-start-conditions/
- https://support.atlassian.com/bitbucket-cloud/docs/push-back-to-your-repository/ https://support.atlassian.com/bitbucket-cloud/docs/push-back-to-your-repository/
- https://support.atlassian.com/bitbucket-cloud/docs/build-test-and-deploy-with-pipelines/ https://support.atlassian.com/bitbucket-cloud/docs/build-test-and-deploy-with-pipelines/
优点:
缺点:
- 您必须记住手动编写
"[skip ci]"
文本。这很容易忘记,或者新的团队成员可能不会知道这一点。
2.使用Git Hook自动修改你的git提交消息
编写一个 Git Hook 脚本,该脚本将自动将“[skip ci]”文本插入到 Git 提交消息中。该脚本必须执行以下操作:
- 本地提交后,查看最新提交查看哪些文件被更改 https://stackoverflow.com/questions/1552340/how-to-list-only-the-names-of-files-that-changed-between-two-commits。使用类似的东西
git diff --name-only HEAD~0 HEAD~1
- If
bitbucket-pipelines.yml
是唯一更改的文件,修改提交以插入"[skip ci]"
到提交消息中。
有关 Git Hook 的更多信息:
- https://githooks.com/ https://githooks.com/
- https://www.atlassian.com/git/tutorials/git-hooks https://www.atlassian.com/git/tutorials/git-hooks
- https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks
优点:
缺点:
- 创建脚本可能并不容易。
- 每个克隆的存储库都需要配置 git hooks。看:Git 挂钩脚本可以与存储库一起管理吗? https://stackoverflow.com/questions/427207/can-git-hook-scripts-be-managed-along-with-the-repository
3. 制作bitbucket-pipelines.yml
检查文件更改
添加一个部分yml
构建脚本来检查最新提交中更改了哪个文件。
yml 中的脚本必须执行以下操作:
- 检查最新的提交以查看哪些文件被更改。使用类似的东西
git diff --name-only HEAD~0 HEAD~1
- If
bitbucket-pipelines.yml
是唯一更改的文件,立即中止 CI 构建,并使用exit 0
陈述。
优点:
- 它是全自动的。无需手动标记您的提交消息。
- 无需编写 Git Hook 脚本。
缺点:
- CI 构建的 Docker 映像将需要 1-5 分钟来加载,然后自行中止。这有点低效,并且会消耗一些构建时间。
- 由于 CI 构建仍将运行几分钟,因此未执行任何操作的构建运行会污染您的 CI 构建历史记录。
4. 使用带有“changesets”和“includePaths”的条件步骤
定义一个changesets
与includePaths
仅当修改的文件之一与中的表达式匹配时才执行步骤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 https://bitbucket.org/blog/conditional-steps-and-improvements-to-logs-in-bitbucket-pipelines
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)