aws-codepipeline - AWS Codecommit - Codebuild 将分支名称传递给 buildspec.yml
问题描述
我正在使用 codecommit、codebuild 和 codepipeline,这样每次我在分支上提交时,相关的管道都会从 codebuild 中的 codecommit 构建(然后是部署/失效)
我的 package.json 中有 3 个不同的脚本,分别称为 build-master、build-test 和 build-prod,分别与 master、test 和 prod 的 3 个分支相关联。
# buildspec.yml
phases:
install:
commands:
- yarn --dev
pre_build:
commands:
- aws configure set preview.cloudfront true
- bash -c 'echo "Build started `date` on bucket s3://xx.xxxxxx.$CODEBUILD_SOURCE_VERSION.web"'
build:
commands:
- bash -c 'yarn build-$CODEBUILD_SOURCE_VERSION'
artifacts:
files:
- '**/*'
base-directory: 'dist'
name: xxxx-xxxx.$(date +%Y-%m-%d-%h-%M-%s).$(CODEBUILD_SOURCE_VERSION)
$CODEBUILD_SOURCE_VERSION 给了我管道的 arn。我尝试了 codebuild 提供的其他变量,但无济于事。
我还尝试使用 bash -c 从 git 获取分支,但在 codebuild 中我无权访问 repo。
有没有办法用我当前的配置获取分支的名称?
解决方案
您可以使用所需的环境变量为每个分支/管道设置不同的 CodeBuild 项目。
推荐阅读
- r - 从 R 代码转换的 F# 无法从 Web 抓取数据
- knowledge-capture - 如何逆向工程或了解网站正在使用的技术?
- wordpress - 如果 wordpress 标题重复,则将帖子 ID 添加到标题
- c# - 处理 DataTemplate 元素更改
- android - 终止 UI 恢复的活动或进程
- java - 如何配置 Java - Eclipse 项目以将 log4j 与 Java 9+ 模块一起使用
- r - 任何帮助表示赞赏。R:创建计算 x 的 sqrt 的函数,如果 x 为负,则返回 Na
- c++ - Linux:与 Alsa 未定义的引用链接
- node.js - Puppeteet 启动浏览器进程失败
- javascript - JS DOM 顺序问题