Setting credentials for https git clone in AWS CodeBuild

10,824

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

Share:
10,824
woodpav
Author by

woodpav

Updated on June 10, 2022

Comments

  • woodpav
    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 so git clone works when CodeBuild runs pip 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
    Avi Flax over 2 years
    This 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
    kewur over 2 years
    this doesnt seem to work with github, I still get permission errors