On top of pull requests auto-build, BuildHive now allows you to push changes directly in via ssh. I call this feature â€œvalidated merge”.
If you are an active developer of a repository, chances are that you donâ€™t use pull requests to send in changes. You probably just push changes directly into your repository instead. But one of the common problems of doing this is that if your change breaks the build, you are going to discover it too late. With validated merge, this problem will never happen again, and this is how it works.
First, you add the buildhive user as a collaborator to your repository, so that it can push when the build is done. I didnâ€™t feel comfortable doing this automatically, so you need to do it explicitly.
Second, login to BuildHive (just once is suffice, so that it learns your public keys you registered with GitHub), head to the job page in BuildHive (like this), and click â€œGit repository for validated merge” link from the left. Click the copy button to copy the â€œgit remote add” command, paste that in your shell, and execute that on your local repository. This will add BuildHive as a remote repository.
Preparation is now complete. Go modify code like you normally do by creating commits, and when you are ready to push, push your changes to â€œjenkins” instead of pushing to â€œorigin”. If you are on a branch, replace â€œmaster” with the branch name you are working on:
$ git push jenkins master
BuildHive will check out the current tip of the specified branch in GitHub, merge that with the changes you just submitted, then do the build and run tests. If the merge result successfully completes the build and tests, the result will be pushed to GitHub by BuildHive.
If you are unlucky and your changes werenâ€™t as good as you thought, youâ€™ll learn that it didnâ€™t pass the builds. You then stash your work, come back to the broken changes, and rework those. You probably don’t remember which commit you pushed to BuildHive, so BuildHive provides a tag you can fetch into your workspace to get to it.
$ git stash $ git fetch -n ssh://email@example.com/kohsuke2/sandbox-ant tag changes/45 $ git checkout changes/45 $ â€¦ make edits ...
You can add more commits to correct the problem, or you can even amend your commits — since your changes didnâ€™t land in the repository, amending, rebasing, and so on is just fine. You can then re-push your changes and then go back to what you were working on before interrupted by a failure.
$ git push jenkins HEAD:master $ git checkout master $ git stash pop â€¦ resume the work you were doing ...
If youâ€™ve already headed home, your colleague can do this workflow for you.
Your time is precious. Donâ€™t waste it by watching your laptop to complete tests. Instead, let BuildHive do it for you!
By the way, this is a feature already available in Jenkins Enterprise by CloudBees, so if you like the workflow but your source code isnâ€™t in a public GitHub repository, you can do the same thing with any Git repository inside your firewall.