简体   繁体   中英

Error while mirroring from Github to AWS CodeCommit

I have an AWS CodeCommit repo created in eu-central-1 . I am planning to Synchronize a repo in GitHub to AWS CodeCommit. All the present code and future PR's merging to main and preprod should be in the AWS CodeCommit. I am using this script to script from GitHub actions in my Jenkins stage

git config --global credential.'https://git-codecommit.*.amazonaws.com'.helper '!aws codecommit credential-helper $@'
git config --global credential.UseHttpPath true
git remote add sync https://git-codecommit.eu-central-1.amazonaws.com/v1/repos/test-repo
git push sync --mirror

I get the following error

fatal: could not read Username for 'https://git-codecommit.eu-central-1.amazonaws.com/v1/repos/test-repo': No such device or address

The job where Jenkins job is running has a role attached to the instance and it has full permissions on CodeCommit. Am I missing any prerequisites or have to execute any prerequisites before mirroring to resolve the above issue?

Note/Disclaimer : I didn't look into (or tested, for that matter) the specific GitHub action that's been referenced, but am providing instructions only on how to make sure that you can sync a "primary" Git repository with a "secondary" Git repository hosted on AWS CodeCommit using an EC2 instance.

When using an EC2 instance (for example to host Jenkins), you should first verify that it has an IAM role attached, and that this IAM role has the necessary IAM Policy attached to read/write to CodeCommmit (for example AWSCodeCommitPowerUser).

If that's the case, you should test next if the EC2 instance can query the CodeCommit repository, for example by executing the following (replacing and of course):

aws codecommit get-repository --repository-name <REPO-NAME> --region <REGION>

If this was successful, you're ready to set up the Git credentials for CodeCommit so that it can be used by the Git CLI. This is done via the git [..] credential command that was already provided in the question, which can also be found in the official AWS docs for CodeCommit :

git config --global credential.helper '!aws codecommit credential-helper $@'
git config --global credential.UseHttpPath true

Next, check if Git can talk to CodeCommit directly (ie without using the AWS CLI), eg by cloning the repository:

git clone https://git-codecommit.<REGION>.amazonaws.com/v1/repos/<REPO-NAME>

Now you should be good to go to sync the changes from the primary repository. So after cloning the primary repository, cd into it and then run the commands to set up the CodeCommit repo as remote, then push the copy.

git remote add sync https://git-codecommit.<REGION>.amazonaws.com/v1/repos/<REPO-NAME>
git push sync --mirror

That should be confirmed successfully and the changes will now be visible in the CodeCommit repository.

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