简体   繁体   English

使用 AWS CodeBuild 进行语义版本控制

[英]Semantic versioning with AWS CodeBuild

Currently my team is using Jenkins to manage our CI/CD workflow.目前我的团队正在使用 Jenkins 来管理我们的 CI/CD 工作流程。 As our infrastructure is entirely in AWS I have been looking into migrating to AWS CodePipeline/CodeBuild to manage this.由于我们的基础设施完全在 AWS 中,我一直在考虑迁移到 AWS CodePipeline/CodeBuild 来管理它。

In current state, we are versioning our artifacts as such <major>.<minor>.<patch>-<jenkins build #> ie 1.1.1-987 .在当前状态下,我们将我们的工件版本化为<major>.<minor>.<patch>-<jenkins build #>1.1.1-987 However, CodeBuild doesn't seem to have any concept of a build number.但是,CodeBuild 似乎没有任何内部版本号的概念。 As artifacts are stored in s3 like <bucket>/<version>/<artifact> I would really hate to lose this versioning approach.由于工件存储在 s3 中,例如<bucket>/<version>/<artifact>我真的很不想失去这种版本控制方法。

CodeBuild does provide a few env variables that i can see here: http://docs.aws.amazon.com/codebuild/latest/userguide/build-env-ref.html#build-env-ref-env-vars CodeBuild 确实提供了一些环境变量,我可以在这里看到: http ://docs.aws.amazon.com/codebuild/latest/userguide/build-env-ref.html#build-env-ref-env-vars

But from what is available it seems silly to try to use the build ID or anything else.但是从可用的内容来看,尝试使用构建 ID 或其他任何东西似乎很愚蠢。

Is there anything readily available from CodeBuild that could support an incremental build #? CodeBuild 中是否有任何可以支持增量构建的现成工具? Or is there an AWS recommended approach to semantic versioning?或者是否有 AWS 推荐的语义版本控制方法? Searching this topic returns remarkably low results搜索此主题返回的结果非常低

Any help or suggestions is greatly appreciated非常感谢任何帮助或建议

The suggestion to use date wasn't really going to work for our use case.使用 date 的建议对我们的用例并不真正有效。 We ended up creating a base version in SSM and creating a script that runs within the buildspec that grabs, increments, and updates the version back to SSM.我们最终在 SSM 中创建了一个基本版本,并创建了一个在构建规范中运行的脚本,该脚本获取、增加并将版本更新回 SSM。 It's easy enough to do:这很容易做到:

  • Create a String/SecureString within SSM as [NAME].在 SSM 中创建一个 String/SecureString 作为 [NAME]。 For example lets say "BUILD_VERSION".例如,让我们说“BUILD_VERSION”。 The value should be in [MAJOR.MINOR.PATCH] or [MAJOR.PATCH].该值应在 [MAJOR.MINOR.PATCH] 或 [MAJOR.PATCH] 中。
  • Create a shell script.创建一个 shell 脚本。 The one below should be taken as a basic template, you will have to modify it to your needs:以下应作为基本模板,您必须根据需要对其进行修改:
#!/bin/bash
if [ "$1" = 'next' ]; then
    version=$(aws ssm get-parameter --name "BUILD_VERSION" --region 'us-east-1' --with-decryption | sed -n -e 's/.*Value\"[^\"]*//p' | sed -n -e 's/[\"\,]//gp')
    majorminor=$(printf $version | grep -o ^[0-9]*\\.[0-9]*\. | tr -d '\n')
    patch=$(printf $version | grep -o [0-9]*$ | tr -d '\n')
    patch=$(($patch+1))
    silent=$(aws ssm put-parameter --name "BUILD_VERSION" --value "$majorminor$patch" --type "SecureString" --overwrite)
    echo "$majorminor$patch"
fi
  • Call the versioning script from within buildspec and use the output however you need.从构建规范中调用版本控制脚本并根据需要使用输出。

It may be late while I post this answer, however since this feature is not yet released by AWS this may help a few people in a similar boat.我发布这个答案可能已经晚了,但是由于 AWS 尚未发布此功能,这可能会帮助一些类似的人。

We used Jenkins build numbers for versioning and were migrating to codebuild/code-pipeline .我们使用 Jenkins 版本号进行版本控制,并正在迁移到codebuild/code-pipeline codebuild-id did not work for us as it was very random. codebuild-id对我们不起作用,因为它非常随机。 So in the interim we create our own build number in buildspec file BUILD_NUMBER=$(date +%y%m%d%H%M%S) .因此,在此interim我们在构建buildspec文件BUILD_NUMBER=$(date +%y%m%d%H%M%S)创建了自己的构建号。

This way at least we are able to look at the id and know when it was deployed and have some consistency in the numbering.通过这种方式,至少我们能够查看 id 并知道它是何时部署的,并且在编号方面具有一定的一致性。 So in your case, it would be 1.1.1-181120193918 instead of 1.1.1-987 .所以在你的情况下,它将是1.1.1-181120193918而不是1.1.1-987

Hope this helps.希望这会有所帮助。

CodeBuild supports semantic versioning . CodeBuild 支持语义版本控制

In the configuration for the CodeBuild project you need to enable semantic versioning (or set overrideArtifactName via the CLI/API).在 CodeBuild 项目的配置中,您需要启用语义版本控制(或通过 CLI/API 设置overrideArtifactName )。

Then in your buildspec.yml file specify a name using the Shell command language:然后在您的buildspec.yml文件中使用 Shell 命令语言指定一个name

artifacts:
  files:
    - '**/*'
  name: myname-$(date +%Y-%m-%d) 

Caveat: I have tried lots of variations of this and cannot get it to work.警告:我已经尝试了很多变体,但无法使其正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM