gitgoogle-cloud-buildgoogle-cloud-source-reposcloudbuild.yaml

Make CloudBuild git push last commits to a branch in another repo


I have branch_a (development branch) in repo_A and branch_b in repo_B (production branch). Both repos are on Cloud Source. Their history is the same, except for the last commit(s) in branch_a.

How to make CloudBuild push last commit(s) from repo_A/branch_a to repo_B/branch_b?

CloudBuild gets triggered with a push to repo_A/branch_a. CloudBuild fetches repo_A/branch_a into the working directory

I managed to add repo_B/branch_b as remote. But when I try to push 'master' to repo_B/branch_b I get:

src refspec branch_b does not match any
failed to push some refs to repo_B

git remote -v lists both remotes: repo_A and repo_B

CloudBuild service account has access to both repos


Solution

  • For the future generations

    The problem was that Cloud Build was pulling only the last commit from repo_A, thus comparing to repo_B/branch_B was showing inconsistent history.

    git pull --unshallow did the trick.