jeudi 21 juin 2018

How to deploy rails via Capistrano and Jenkins using GitHub

I am new to Jenkin and I need to deploy rails application with jenkin. I am using capistrano task to deploy rails application to ec2 server.

Our devops teams are maintaining the jenkin server and they creted a credential to fetch the latest repo from github. I am not sure if I have to use their credential or not or if yes how can I use their credential

deploy@localhost:~/rails_project (staging)$ bundle exec cap staging deploy
* executing `staging'
  triggering start callbacks for `deploy'
* executing `multistage:ensure'
* executing `deploy'
* executing `deploy:update'
** transaction: start
* executing `deploy:update_code'
  updating the cached checkout on all servers
  executing locally: "git ls-remote git@github.com:Private-Repo/rails_project.git staging"
  command finished in 4387ms
* executing "if [ -d /home/ec2-user/rails_project/shared/cached-copy ]; then cd /home/ec2-user/rails_project/shared/cached-copy && git fetch -q origin && git fetch --tags -q origin && git reset -q --hard 2349f182417bc5932c7cdefcfeecac12b98ade28 && git clean -q -d -x -f; else git clone -q git@github.com:Private-Repo/rails_project.git /home/ec2-user/rails_project/shared/cached-copy && cd /home/ec2-user/rails_project/shared/cached-copy && git checkout -q -b deploy 2349f182417bc5932c7cdefcfeecac12b98ade28; fi"
servers: ["111.111.111.111"]
* establishing connection to gateway `"bastion_user@bastion.server.com"'
* Creating gateway using bastion_user@bastion.server.com
* establishing connection to `111.111.111.111' via gateway
[111.111.111.111] executing command
** [111.111.111.111 :: out] Failed to add the RSA host key for IP address '192.xx.xxx.xxx' to the list of known hosts (/home/ec2-user/.ssh/known_hosts).
** [111.111.111.111 :: out] Permission denied (publickey).
** [111.111.111.111 :: out] fatal: Could not read from remote repository.
** 
** Please make sure you have the correct access rights
** and the repository exists.
command finished in 1925ms
*** [deploy:update_code] rolling back
* executing "rm -rf /home/ec2-user/rails_project/releases/20180621070926; true"
servers: ["111.111.111.111"]
[111.111.111.111] executing command
command finished in 1422ms
failed: "env RAILS_ENV=staging sh -c 'if [ -d /home/ec2-user/rails_project/shared/cached-copy ]; then cd /home/ec2-user/rails_project/shared/cached-copy && git fetch -q origin && git fetch --tags -q origin && git reset -q --hard 2349f182417bc5932c7cdefcfeecac12b98ade28 && git clean -q -d -x -f; else git clone -q git@github.com:Private-Repo/rails_project.git /home/ec2-user/rails_project/shared/cached-copy && cd /home/ec2-user/rails_project/shared/cached-copy && git checkout -q -b deploy 2349f182417bc5932c7cdefcfeecac12b98ade28; fi'" on 111.111.111.111

But jenkin is using a credential and it can fetch repo grom github, how can I use github, capistrano and jenkin with github key together. If more information needed please do ask, Thanks

Aucun commentaire:

Enregistrer un commentaire