[英]Access from Jenkins(in Docker image) to BitBucket repository
Our team is trying for days to get this accessbut we arre tottally stucked on how todo.我们的团队已经尝试了好几天才能获得此访问权限,但我们完全不知道该怎么做。
At very initial part to get access to directory, following the steps:在开始访问目录的部分,请按照以下步骤操作:
Created keys with linux ssh keygen
command and put public key on Bitbucket repository Security Settings.使用 linux ssh keygen
命令创建密钥并将公钥放入 Bitbucket 存储库安全设置。
after logged in Jenkins I start a new task,then Freestyle build and Go登录后 Jenkins 我开始一个新任务,然后是自由式构建和 Go
Inside task I hit "Settings" go to Source code configurations, select git and put the repository as: git@bitbucket.org:my_company/my_repo.git在任务中,我点击“设置”go 到源代码配置,select git 并将存储库设置为:git@bitbucket.org:my_company/my_repo.git
On credentials I click on Add/Jenkins: and configure "Kind" as "SSH Username with private key", write my Username, in Private Key click on Enter Directly and paste my Private SSH key in field, Finish clicking in ADD.在凭据上,我单击添加/詹金斯:并将“Kind”配置为“带私钥的 SSH 用户名”,写入我的用户名,在私钥中单击直接输入并将我的私钥 SSH 粘贴到字段中,完成单击添加。
I choose the new credential created...我选择创建的新凭据...
get RED error message - and can't access BitBucket repo:收到红色错误消息 - 并且无法访问 BitBucket 存储库:
Failed to connect to repository : Command "git ls-remote -h -- git@bitbucket.org:cryptoblock/cblock1.git HEAD" returned status code 128:
stdout:
stderr: No RSA host key is known for bitbucket.org and you have requested strict checking.
Host key verification failed.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
I tried to change many times the generated keys我试图多次更改生成的密钥
I tried to put the private key at machine that hosts docker container with jenkins我试图将私钥放在托管 docker 容器和 jenkins 的机器上
I entered on container with jenkins and put private key at /root/.ssh directory我使用 jenkins 进入容器并将私钥放在 /root/.ssh 目录中
I entered on container with jenkins logged dave sudo permissions to jenkins user and put private key at ~/.ssh directory我进入容器 jenkins 登录 dave sudo 权限到 jenkins 用户并将私钥放在 ~/.ssh 目录
jenkins@jenkins_host $ ssh-keyscan -H bitbucket.com >> ~/.ssh/known_hosts
But I receive answer: bash: /var/jenkins_home/.ssh/known_hosts: Permission denied
even trying as sudo ( changing sudoers file)但我收到答案: bash: /var/jenkins_home/.ssh/known_hosts: Permission denied
even try as sudo (changing sudoers file)
After some research on @mzm answer I build out a solution following this steps:在对@mzm 的回答进行一些研究后,我按照以下步骤构建了一个解决方案:
1 - Create ssh key-pair with ssh-keygen
1 - 使用ssh-keygen
创建 ssh 密钥对
Then:然后:
2 - Install Docker with Jenkins and run its docker 2 - 安装 Docker 和 Jenkins 并运行其 docker
3 - on host (where docker is running), execute: 3 - 在主机上(运行 docker 的地方),执行:
docker ps
( get container ID) a) docker ps
(获取容器 ID)docker exec -u 0 -it <ID> /bin/bash
b) docker exec -u 0 -it <ID> /bin/bash
apt update
c) apt update
apt install sudo
d) apt install sudo
apt install nano
e) apt install nano
sudo visudo
f) sudo visudo
jenkins ALL=(ALL) NOPASSWD:ALL
g) 在将打开的文件中插入此行: jenkins ALL=(ALL) NOPASSWD:ALL
exit
h) 以 root 身份退出 jenkins docker: exit
check jenkins docker ID, with docker ps
检查 jenkins docker ID, docker ps
4 - Enter in jenkins docker with command exec -it <ID> /bin/bash
and execute in order: 4 - 使用命令exec -it <ID> /bin/bash
输入 jenkins docker 并按顺序执行:
mkdir /var/jenkins_home/.ssh
b) 创建文件夹: mkdir /var/jenkins_home/.ssh
cd /var/jenkins_home/.ssh
c) 进入文件夹: cd /var/jenkins_home/.ssh
touch known_hosts
d) 创建文件: touch known_hosts
ssh-keyscan -H bitbucket.org > known_hosts
e) 将扫描结果放入创建的文件中: ssh-keyscan -H bitbucket.org > known_hosts
After that should be possible to jenkins connect through ssh with Bitbucket.之后应该可以将 jenkins 通过 ssh 与 Bitbucket 连接起来。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.