Capistrano deploy fails after I changed the repository URL
Solution 1
I gotta say I’m not sure, since I haven’t been able to test this but this should work:
cap deploy:cleanup -s keep_releases=0
Since it wipes every release (cache) from the server.
Apparently you will also need to remove shared/cached-copy
, because this doesn’t seem to be cleaned by the Capistrano call above according to the comment below.
Solution 2
Capistrano 2.X
Delete and re-clone the repo using the new address:
cd $deploy_to/shared
rm -rf cached-copy
git clone ssh://[email protected]/new/repo.git cached-copy
Modify your config/deploy.rb
to use the new repo:
set :repository, "ssh://[email protected]/new/repo.git"
set :scm, :git
set :deploy_via, :remote_cache
Deploy again:
cap deploy
Capistrano 3.X
- Remove the
$deploy_to/repo
directory - Modify your
config/deploy.rb
(same as 2.X) cap deploy
Solution 3
Capistrano 2 and below
SSH to your server and update the repo in ./shared/cached-copy/.git/config
of the deployment folder, or just remove the ./shared/cached-copy
Capistrano 3 and above
SSH to your server and update the repo in ./repo/config
of the deployment folder.
Check Fixing Capistrano 3 deployments after a repository change
Solution 4
I solved this with the following in deploy.rb
:
namespace :deploy do
task :cope_with_git_repo_relocation do
run "if [ -d #{shared_path}/cached-copy ]; then cd #{shared_path}/cached-copy && git remote set-url origin #{repository}; else true; fi"
end
end
before "deploy:update_code", "deploy:cope_with_git_repo_relocation"
It makes deploys a little slower, so it's worth removing once you're comfortable that all your deploy targets have caught up.
Solution 5
You need to change git origin in your /shared/cached-copy folder
cd /var/www/your-project/production/shared/cached-copy
git remote remove origin
git remote add origin [email protected]:/origin.git
try cap production deploy
Jakub Arnold
Experienced software engineer with a background in machine learning and computer science and over 7 years of commercial practice of software development, looking to work on production quality software.
Updated on June 06, 2022Comments
-
Jakub Arnold almost 2 years
I have a simple deployment via capistrano from a Git repository. At first I was deploying form GitHub, everything worked just fine. But then I moved my repository to BitBucket and now I'm getting
fatal: Could not parse object '9cfb...'.
The problem goes away once I change
set :deploy_via, :remote_cache
to
set :deploy_via, :copy
but that doesn't fix the problem, it only bypasses it. Is there any way I can tell capistrano to just drop the old cache?
-
Jakub Arnold over 12 yearsThis didn't solve the problem entirely, but once I removed
shared/cached-copy
, it deploys just fine now. -
JD. over 11 yearsIt did not work for me, either, but Jakub's comment here did.
-
nil over 11 yearsyou can just change the url of origin remote to your new repo address in the
shared/cached-copy
directory. -
Kenny Lövrin almost 11 yearsI'd say this is the better answer. If you delete all releases you are essentially in bad shape if your new deploy fails and you cannot roll back. I also think it is worth noting that cloning the repo manually is only needed to add the host to the known hosts. If it already is added then the deploy will work (so essentially the same thing as when setting up capistrano for the first time, checking out the repo anywhere works just to get it added)
-
Justin Tanner almost 11 years@KennyLövrin yes cloning the repo anywhere will get your host into the known hosts, but aif you have
:remove_cache
set you need something in the cached-copy directory or capistrano won't deploy. -
eveevans almost 11 yearsthe answer only delete all releases on server (including current). The best answer (if you have remote cache active) is that of Jakub Arnold.
-
Fred Oliveira over 10 yearsKeep in mind that capistrano 3.1 uses
shared/repo
instead ofshared/cached-copy
so this answer, while almost correct, should be updated. -
Roxas Shadow over 9 yearsIn capistrano 3.2.1 I solved removing the
$deploy_to/repo
folder since I cannot found anyrepo
folder inshared
. -
sixty4bit over 9 yearswhere are all these directories? I'm having a similar problem in a Rails 3.2 app and have no idea what's going on. I develop on OS X and have no trouble deploying but my coworker, who is using a nitrous.io linux box, is getting errors on deploy that the repo can't be found despite the git remote being set and the master branch being up to date
-
hemc4 over 9 yearsThis link Worked, shared/cached-copy and deploy:cleanup doesn't work with capistrano 3
-
Rodrigo Zurek about 9 yearsadd jakub comment to the answer, it solves the issue
-
csch almost 9 yearsSince Capistrano 3 you have to delete
/repo
instead ofshared/cached-copy
. Edit: See Justin Tanner's answer -
Brettski over 8 yearsThis is the better answer
-
ppires over 8 yearsIt's not necessary to delete the entire
repo
folder, just editrepo/config
and change the repo URL to the new one. -
ObjectNameDisplay over 7 yearsJustin Tanner's answer doesn't require removing old releases and is simpler.
-
gl03 about 7 yearsThis is quite dangerous if your deploy fails, since no rollback will be possible and you'll be crying at a blank screen where your website was. (empirically tested)
-
a2f0 over 6 yearsI was able to get by without, git clone ssh://[email protected]/new/repo.git cached-copy, working solution, though thanks 👍
-
mmike over 6 yearsnice solution. let's say that
./repo/config
->path_to_your_repo/repo/config
(it's not clear for beginning)