问题描述
每次推送到存储库和每次拉取请求都会触发我的构建.
My build is triggered on every push to the repo and on every pull request.
所以 CODEBUILD_SOURCE_VERSION 看起来像pr/8"或4570d2e7158cfef687af8da31d1ffec7b02e5ca3".
So CODEBUILD_SOURCE_VERSION looks like "pr/8" or "4570d2e7158cfef687af8da31d1ffec7b02e5ca3".
我只希望构建为 pr 分支执行并推送到 master.实现这一目标的最佳方法是什么?我不想使用 CodeDeploy,因为我只是在部署 lambdas.
I only want the build to execute for pr branches and pushes to master. What is the best way to achieve this? I don't want to use CodeDeploy as I am just deploying lambdas.
我可以编写一个 bash 函数,在安装阶段检查 CODEBUILD_SOURCE_VERSION 并执行退出 1.但这会在我们的 slack 通道中产生很多误报,因为这些并不是真正的失败构建".
I could write a bash function that checks CODEBUILD_SOURCE_VERSION on the install phase and does an exit 1. But this will create a lot of false positives in our slack channel as these are not really "failed builds".
推荐答案
您的方法将取决于触发构建事件的原因,然后您必须将这些事件路由到代码构建.如果您使用的是 Github,则可以通过创建一个在 push 和 pull_request 事件上触发的 webhook 来明确标记要触发系统的事件.该 webhook 向您的系统发送一个 post 请求,这将需要一些代码将该请求转换为启动 codebuild 构建.我认为您不想在构建开始后解析事物以查看构建是否应该继续.如果它不应该运行,最好不要开始构建.
Your approach is going to depend on what is triggering your build events and then you'll have to route those events to codebuild. If you're using Github, you could explicitly mark which events you want to trigger your system by creating a webhook that fires on push and pull_request events. That webhook sends a post request into your system, which is going to need some code to convert that request into starting a codebuild build. I don't think you want to parse things after the build has started to see if the build should continue. It is better to not start the build at all if it shouldn't run.
这篇关于AWS CodeBuild - 如何跳过构建的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!