Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS CodeBuild default environment variables.

I created a Pipeline that takes the code from a CodeCommit repository, builds it via CodeBuild and pushes the code to an S3 bucket.

For my Codebuild I'm using an AWS managed image. aws/codebuild/nodejs:7.0.0

If I start my build manually via the CodeBuild Console and specify the repository I get the repository URL when I run the following command in the buildspec

- printf ${CODEBUILD_SOURCE_REPO_URL}

but If the CodeBuild is triggered automatically by a push to a repository. CODEBUILD_SOURCE_REPO_URL returns nothing

like image 393
Qais Abou Jaoudé Avatar asked Apr 18 '26 03:04

Qais Abou Jaoudé


2 Answers

If you're connecting via CodeCommit, you can split strings to get more useful values such as Account Id and Repo Name using:

echo "Region = ${AWS_REGION}"
echo "Account Id = $(echo $CODEBUILD_BUILD_ARN | cut -f5 -d ':')"
echo "Repo Name = $(echo $CODEBUILD_SOURCE_VERSION | cut -f2 -d '/')"
echo "Commit Id = ${CODEBUILD_RESOLVED_SOURCE_VERSION}"

Which outputs:

Region = us-west-2
Account Id = 0123456789
Repo Name = my-app
Commit Id = a46218c9160f932f2a91748a449b3f9818964642
like image 111
Kim T Avatar answered Apr 20 '26 17:04

Kim T


If you are running the process from codepipeline it would be empty.

Check this out: https://docs.aws.amazon.com/codebuild/latest/userguide/build-env-ref-env-vars.html

CODEBUILD_SOURCE_REPO_URL: The URL to the input artifact or source code repository. For Amazon S3, this is s3:// followed by the bucket name and path to the input artifact. For AWS CodeCommit and GitHub, this is the repository's clone URL. If a build originates from AWS CodePipeline then this may be empty.

like image 21
Carlos Andres Zambrano Barrera Avatar answered Apr 20 '26 18:04

Carlos Andres Zambrano Barrera



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!