Setting credentials for https git clone in AWS CodeBuild
Solution 1
Since the CodeBuild environment uses an IAM role for credentials (not a username and password), you will need to configure the CodeCommit credential helper in your buildspec:
phases:
install:
commands:
- git config --global credential.helper '!aws codecommit credential-helper $@'
- git config --global credential.UseHttpPath true
Solution 2
CodeBuild now provides an easier dial for this buildspec by setting the "git-credential-helper" to yes. Documentation @ https://docs.aws.amazon.com/codebuild/latest/userguide/build-spec-ref.html#build-spec-ref-syntax
Solution 3
You can use de credentils helper from git, you can put the following commands into builspec pipeline
phases:
install:
commands:
- echo "https://username:[email protected]" > ~/.git-credentials
- git config credential.helper 'store'
Git documentation https://git-scm.com/docs/git-credential-store
woodpav
Updated on June 10, 2022Comments
-
woodpav almost 2 years
I am running a CodeBuild on a project that has private requirements stored in CodeCommit.
I need to add a command in
buildspec.yml
that loads the https git credentials sogit clone
works when CodeBuild runspip install
.The build fails with
fatal: could not read Username for 'https://git-codecommit.us-west-2.amazonaws.com': No such device or address
-
Avi Flax over 2 yearsThis is a helpful answer, but FWIW I find that documentation useless. It doesn’t give any context, guidance, etc. I have no idea how to actually use the feature.
-
kewur over 2 yearsthis doesnt seem to work with github, I still get permission errors