Tuesday, October 15, 2013

// // 1 comment

Automating PhoneGap Build build.

No - that's not a typo. I'm referring to the build process when using Adobe's phonegap build service. I won't go on much about phonegap build, except to say that it's brilliant and probably saved me from buying an expensive mac for 2 weeks of development work. Can't completely eliminate the need for a mac, but at least day-to-day phone gap based web development does not require one.

Phonegap build offers you the ability to zip up your web application and upload it for a build. 2 easy steps right ? Wrong! Doing this around 50 times a days is quite annoying and repetitive. So naturally, I looked around for a simpler way to do this

1. Zipping up files

I use 7-zip, which comes will a command line interface. I had to add the install location to the PATH, and then it was as simple as issuing

7z a [targetpackage.zip] [targetdirectory]

2. Uploading to phonegap build 

Luckily phone gap provides an http API to interface with it. It's sparsely documented, but fairly intuitive. Since I was uploading a zipped file instead of using a github repository, the command was

curl -u [username]:[password] -X PUT -F file="@[full-file-path]" https://build.phonegap.com/api/v1/apps/[appid]

You can download curl for windows from here 

A few gotchas

  • For windows users, the fill-file-path needs to be enclosed in double quotes. This is more of a curl quirk than anything to do with phonegap build.
  • Finding the application id: the application id used in the curl URL can be sourced quite easily from phonegap build URL for your project. For instance when navigating via the browser to your app, the URL is https://build.phonegap.com/apps/598899/builds , then 598899 would be the appId that needs to be plugged in to the curl command at [appid]
  • Excluding git files: I'm using git as source control and this creates a .git\ sub directory. The problem is that i don't want this to be part of the zipping process. adding -xr!?git\* to the zip command does the job nicely.
  • Reset the archive: the zip command adds to an existing archive, which means that if i delete files off my directory, they won't get removed from the archive. So - I delete the target archive before zipping.

All of this is taken and put up into a batch file 

del [target-archive]
7z a [target-archive] [target-directory] -xr!?git\*
curl -u [username]:[password] -X PUT -F file="[target-archive]" https://build.phonegap.com/api/v1/apps/[appId]







1 comment:

  1. Anonymous3:28 AM

    This worked great! Totally am using this to automate our build process using the PhoneGap Build service.

    ReplyDelete