Semantic versioning with AWS CodeBuild

My team is currently using Jenkins to manage our CI / CD workflow. Since our infrastructure is entirely in AWS, I tried to migrate to AWS CodePipeline / CodeBuild to handle this.

In the current state, we create versions of 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 build number. Since artifacts are stored in s3, for example, <bucket>/<version>/<artifact>

I would hate to lose this approach to version control.

CodeBuild provides several env variables which 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 an assembly id or whatever.

Is there anything readily available in CodeBuild that can support incremental build #? Or is there AWS a recommended approach for semantic versioning? Searching on this topic gives very low results

Any help or suggestions are greatly appreciated

+9


source to share


2 answers


While I'm posting this answer, it might be late since this feature hasn't been released by AWS yet, it might help a few people on a boat like this.

We used Jenkins build numbers for version control and switched to codebuild/code-pipeline

. codebuild-id

didn't work for us as it was very random. Therefore, in interim

we create our own build number in the file buildspec

BUILD_NUMBER=$(date +%y%m%d%H%M%S)

.



So at least we can look at the ID and know when it was expanded and have some sequence in the numbering. So in your case it will be 1.1.1-181120193918

instead 1.1.1-987

.

Hope this helps.

+1


source


The suggestion to use a date didn't actually work for our use case. We ended up creating a base version in SSM and creating a script that runs within buildspec that grabs, grows, and updates the version back to SSM. It's easy enough to do this:

  • Create string / SecureString in SSM as [NAME]. For example, let's say "BUILD_VERSION". The value must be in [MAJOR.MINOR.PATCH] or [MAJOR.PATCH].
  • Create a shell script. The below should be considered as a basic template, you will have to modify it according 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 source control script from within buildspec and use the output as you need.
0


source







All Articles