11

Currently my team is using Jenkins to manage our CI/CD workflow. As our infrastructure is entirely in AWS I have been looking into migrating to AWS CodePipeline/CodeBuild to manage this.

In current state, we are versioning our artifacts as such <major>.<minor>.<patch>-<jenkins build #> i.e. 1.1.1-987. However, CodeBuild doesn't seem to have any concept of a build number. As artifacts are stored in s3 like <bucket>/<version>/<artifact> I would really hate to lose this versioning approach.

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

But from what is available it seems silly to try to use the build ID or anything else.

Is there anything readily available from CodeBuild that could support an incremental build #? Or is there an AWS recommended approach to semantic versioning? Searching this topic returns remarkably low results

Any help or suggestions is greatly appreciated

justin shores
  • 687
  • 7
  • 24
  • not at this point, but they continue to add features every month, let's wait and hope ... keep an eye on [reddit](https://www.reddit.com/r/aws/). Even **CodeCommit** had no way to see a list of branches and we have it now... it's a slow service, remember that last year, it was not even available in Europe. For now, keep Jenkins (that's what we do for some of the projects) – balexandre Jul 25 '17 at 13:57

3 Answers3

4

The suggestion to use date wasn't really going to work for our use case. 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. It's easy enough to do:

  • Create a String/SecureString within SSM as [NAME]. For example lets say "BUILD_VERSION". The value should be in [MAJOR.MINOR.PATCH] or [MAJOR.PATCH].
  • Create a shell script. 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.
TaDaa
  • 224
  • 3
  • 5
2

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.

We used Jenkins build numbers for versioning and were migrating to codebuild/code-pipeline. codebuild-id did not work for us as it was very random. So in the interim we create our own build number in buildspec file 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. So in your case, it would be 1.1.1-181120193918 instead of 1.1.1-987.

Hope this helps.

grrigore
  • 1,050
  • 1
  • 21
  • 39
bhakti
  • 61
  • 5
-3

CodeBuild supports semantic versioning.

In the configuration for the CodeBuild project you need to enable semantic versioning (or set overrideArtifactName via the CLI/API).

Then in your buildspec.yml file specify a name using the Shell command language:

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

Caveat: I have tried lots of variations of this and cannot get it to work.

steinybot
  • 5,491
  • 6
  • 37
  • 55