Bitbucket windows script to download all team repositories

0
1101

If you join a bitbucket team the first thing your probably going to want to do is download all of the repositories. I know this isn’t my usual “format” for a blog but due to it’s usefulness this is just going to be a script to download all of your team repositories from bitbucket. The below script is a powershell script. You’ll need to setup your system to allow running unsigned scripts for this to run, but it works for me!

if (-not($args[2])) {
 "Usage: [team] [username] [password]"
} else {
	$storageDir = $pwd
	$webclient = new-object System.Net.WebClient
        $nexturl = "https://api.bitbucket.org/2.0/repositories/$($args[0])/"
        $cred = "$($args[1]):$($args[2])"
        $enc_cred = [convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($cred))
        $webclient.Headers.Add("Authorization","Basic $enc_cred")
        Do {
		$webpage = $webclient.DownloadString($nexturl)        
		$teamrepos = ConvertFrom-Json $webpage
  	    	ForEach($val in $teamrepos.values) {
                        git clone $val.links.clone[1].href
          	}
		$nexturl = $teamrepos.next
        } While($nexturl)
	"OK"
}

Simply save this code in a text file named bitbucket_massco.ps1 or any file with the extension ps1 and execute it from the directory where you want the repositories installed. Then run it from powershell. I admit I don’t use powershell often but when you need to automate things on windows it is a fast solution.

On a more personal note, I was just rejected by the Toptal freelancer network due to “lack of problem solving skills”. In reality I simply didn’t have enough time to solve the problems they put in front of me. It literally took me more time to understand the questions than it took for me to code a solution, but the clock was ticking … I’m sure it’s a great network of fresh MIT grads but in all seriousness I’ve been programming professionally for 15 years and not a single one of the problems was anything I’ve ever been required to solve for any client or employer.  As much as I don’t like Upworks new policies since they merged with Elance, at least they’re not discriminatory.  I have a decent resume, have worked for experts in the financial industry on 2 government funded contracts and never once has anyone insulted my “problem solving skills” until now. What I can suggest to most companies out there, take a look at Upwork for your programmers.  99% of the work companies need can be done by Upwork developers.  If you really require fresh MIT graduates, or an equivalent,  than Toptal may be a good solution for you, but none of those MIT graduates have provided you with a script to automate downloading repositories from bitbucket!

SHARE
Previous articleWhy you should, but probably won’t hire me
Next articleGradle vs Maven false advertising and industrial sabotage?
Programming is my passion, and I am constantly working on making my mark in this industry by creating new technologies which open doors to new capabilities. While some of my projects are experimental, most of it is grounded in standard compliant design with a constant focus on security.

LEAVE A REPLY

Please enter your comment!
Please enter your name here