Pushing repository to remote after a successful build

I have a bamboo plan set up to pull from a bitbucket repository. It builds every time a push is made to the repo. If and only if the plan successfully completes, I want to push the changes (the ones I originally pushed to bitbucket which triggered the plan) to a remote git server.

 

So far I did the following:

  • The first stage pulls the repo, and shares the '.git' directory as an artifact
  • A few stages build and test the repository
  • The last stage has the '.git' repository as an artifact dependency. I use a script to add the remote repo and then push to it.

If I set the 'Source Code Checkout' task to 'Force Clean Build' this works and every commit I make is built on the server, then pushed to the remote repository. This is what I want.

 

However if I don't force a clean build, the first build's push is sent to the remote, but consequent builds are not. If I navigate to the Job's directory (for me /var/atlassian/application-data/bamboo/xml-data/build-dir/<JOB_NAME>) and run 'git status' I get: "HEAD detached at 0631325" - showing the short version of the hash of the latest commit.


I'm not familiar enough with git to understand exactly how to deal with this in an efficient manner. I know pulling the repo again completely to another location would technically work, but I feel that that is unnecessary since to build the plan the repo was pulled already. The files are already there.

 

Is there a recommended way that I could push the changes from this headless repo to a remote repo, instead of pushing from the outdated origin branch?

 

 

1 answer

1 accepted

I ended up resolving this issue by explicitly pushing from the head:

git push backup HEAD:master
git push backup HEAD:master --tags

where 'backup' is a remote set via https:

git remote add backup https://USER:PASSWORD@URL/TO/REPO.git

Suggest an answer

Log in or Join to answer
Community showcase
Renan Battaglin
Published May 18, 2017 in Bamboo

FAQ: How to Upgrade Bamboo Server

Bamboo 5.9 will no longer be supported after June 12, 2017. What does this mean? As part of our End of Life policy, Atlassian supports major versions for two years after the first major iteratio...

1,066 views 0 5
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot