简体   繁体   English

从在EC2(Ubuntu)上运行的Jenkins访问AWS CodeCommit

[英]Access AWS CodeCommit from Jenkins running on EC2 (Ubuntu)

I'm trying to integrate Jenkins with AWS CodeCommit. 我正在尝试将Jenkins与AWS CodeCommit集成。 Jenkins is running on an AWS EC2 Instance with Ubuntu 14.04. Jenkins在带有Ubuntu 14.04的AWS EC2实例上运行。

I followed this Blogpost: http://blogs.aws.amazon.com/application-management/post/Tx1C8B98XN0AF2E/Integrating-AWS-CodeCommit-with-Jenkins 我关注了此博客文章: http : //blogs.aws.amazon.com/application-management/post/Tx1C8B​​98XN0AF2E/Integrating-AWS-CodeCommit-with-Jenkins

The problem is, that sudo -u jenkins aws configure isn't executed because the jenkins user has no permissions. 问题是,由于jenkins用户没有权限,因此不会执行sudo -u jenkins aws configure

What would you do? 你会怎么做?

The following commands aren't working as well: 以下命令无法正常运行:

sudo -u jenkins git config --global credential.helper '!aws codecommit credential-helper $@'
sudo -u jenkins git config --global credential.useHttpPath true
sudo -u jenkins git config --global user.email "me@mycompany.com"
sudo -u jenkins git config --global user.name "MyJenkinsServer"

What rights does the jenkins user need? jenkins用户需要什么权限?

Thanks in advance. 提前致谢。

I was able to achieve this integration using SSH. 我能够使用SSH实现此集成。 To some extent, I followed these instructions: Setting up for CodeCommit 在某种程度上,我遵循了以下说明: 设置CodeCommit

Assuming Jenkins Home is /var/lib/jenkins/ 假设Jenkins Home是/ var / lib / jenkins /

  1. Create an ssh key on the Jenkins EC2 instance (/var/lib/jenkins/.ssh/id_rsa) 在Jenkins EC2实例(/var/lib/jenkins/.ssh/id_rsa)上创建ssh密钥

     ssh-keygen -b 2048 -t rsa -f /var/lib/jenkins/.ssh/id-rsa -a -N 
  2. Upload the public key to an IAM user (IAM user must have CodeCommit access) 将公钥上载到IAM用户(IAM用户必须具有CodeCommit访问权限)

     aws iam upload-ssh-public-key --user-name <username> --ssh-public-key-body file:///var/lib/jenkins/.ssh/id_rsa.pub 
  3. Collect the SSHPublicKeyID when you upload the key 上载密钥时收集SSHPublicKeyID

     { "SSHPublicKey": { "UserName": "jenkins", "Status": "Active", "SSHPublicKeyBody": "ssh-rsa <rsa-key> <host>\\n", "UploadDate": "2015-09-02T19:18:24.309Z", "Fingerprint": "xxx", "SSHPublicKeyId": "APK***" } } 
  4. Create/modify SSH config file 创建/修改SSH配置文件

     Host git-codecommit.*.amazonaws.com User APK******* IdentityFile /var/lib/jenkins/.ssh/id_rsa StrictHostKeyChecking no 
  5. Where the APK*** is the value of the Key ID retrieved in step 3 其中APK ***是在步骤3中检索到的密钥ID的值

  6. Copy or move this file to /var/lib/jenkins/.ssh/config (or wherever Jenkins is installed on your EC2 instance) 将此文件复制或移动到/var/lib/jenkins/.ssh/config(或在您的EC2实例上安装了Jenkins的任何位置)
  7. Ensure 'jenkins' user has 0600 permissions to /var/lib/jenkins/.ssh directory 确保'jenkins'用户对/var/lib/jenkins/.ssh目录具有0600权限
  8. Create a Jenkins job as described in the blog post you first used. 按照您首次使用的博客文章中的描述创建一个Jenkins职位。 For the repository URL, however, enter the SSH url instead. 但是,对于存储库URL,请输入SSH URL。 (no credentials needed) (无需凭据)

After doing all of above steps. 完成上述所有步骤之后。 If it is still not works. 如果仍然无法使用。 clone any branch within /var/lib/jenkins/.ssh. 克隆/var/lib/jenkins/.ssh中的任何分支。 It will add known host entry. 它将添加已知的主机条目。

sudo -u jenkins git clone ssh://git-codecommit.<your-region>.amazonaws.com/v1/repos/<your test branch>`

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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