简体   繁体   中英

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

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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