Monthly Archives: July 2015

Visual Studio Online’s build: Azure Powershell fail the build

visual_studio_online_build_tasks

Visual Studio Online has many tasks: tasks for building .NET solutions, tasks for building Android, tasks for running bash scripts, tasks for running batch files.  If you want to run in the context of your Azure subscription, you use the Azure Powershell task.  I use this task to do some funny footwork in deploying successful results to an Azure Web App.

The problem:

& $env:BUILD_SOURCESDIRECTORY\the.exe
$e = $LASTEXITCODE
Write-Host "Exit code: $e"
exit $e

So I’m cruising along, my exe returns a non-zero status code to mean “please fail the build”, and Visual Studio Online happily succeeds.  I’m clearly returning 1 from my Azure Powershell task, but it’s not getting the message.

A few hours of pulling out grey hairs, and I’m given a great gift from Chris Patterson.  (Scott Hunter: your team rocks.)  Turns out that the Azure Powershell task isn’t run from powershell.exe, so it doesn’t harvest exit codes.  The solution was simple once he handed it to me.

The Solution:

& $env:BUILD_SOURCESDIRECTORY\the.exe
$e = $LASTEXITCODE
Write-Host "Exit code: $e"
if ($e -ne 0) {
    Write-Error -Message "##[error]BUILD FAILED: $e"
}
exit $e

By using Write-Error, the build correctly fails when it needs to, and life is good.  Chris mentions that he’d like to see it work differently, but it didn’t make RTM.  If you’d like this idea to come in-the-box, vote up my Pull Request … because the task is open-source.  Awesome!

Upgrade Android on a Rooted Device

When Android says “System update available”, we all gleefully run it. Those of us with rooted phones get a way through it and come to an android lying on its back, and a sinking feeling in the pit of our stomach. “Did I just brick my phone?” No, but we did break some of the assumptions the Android updater makes. It presumes we’re running the stock bootloader, which we aren’t. Here’s instructions for getting the bootloader back to stock, getting Android updated using the normal means, and getting re-rooted. This guide assumes your phone is unlocked. (Unlocking your phone will wipe it. Backup before unlocking. Yes, really.)

I. Get ready

  1. Charge the phone. If the phone dies while you’re flashing, you’ve bricked
    the phone. It’s not permanent, but it’s harder.
  2. Install android sdk. I downloaded “adb-tools_treiber.zip” some time ago
    from a source I don’t remember.
    Minimal ADB and fastboot is sufficient.
    The goal is that you have `adb` and `fastboot` command-line commands available.
  3. Get phone drivers. You need drivers both for the regular boot mode and for
    the recovery console. Universal ADB Driver worked
    nicely for me.
  4. Turn on developer mode: Go to Settings > About phone and hit the build
    number 7 times.
  5. Turn on USB Debugging on the phone: Go to Settings > Developer Options > USB
    Debugging
  6. Ensure you have drivers installed. With your phone plugged into the PC via
    USB, open a command prompt, and run these commands:

    • `adb devices`: make sure your device is listed as `device` (not `offline`).
      Click “yes allow USB debugging” on the phone, and run it again until it says
      `device`. If it doesn’t, check Device Manager, try a different driver, or
      check the USB connection.
    • `adb reboot bootloader`: reboot the phone into bootloader so you can check
      the fastboot driver.
    • `fastboot devices`: ensure your phone is listed as `fastboot`.
  7. Backup everything. Double-check everything. What if your phone never
    booted again? What would you lose? It’s your foot…

II. Put bootloader back to stock

Source

  1. Download factory image for current version of Android: https://developers.google.com/android/nexus/images?hl=en. Settings > About Phone shows you your phone’s current version.
  2. Unzip `recovery.img`, `boot.img`, and `system.img`.
  3. Run these commands from a console / terminal in the directory with the unzipped content and adb/fasboot commands. (Run the lines that start with `>` without actually typing the `>`):
  4. # Make sure the device is recognized
    > adb devices
    
    # Boot into bootloader mode
    > adb reboot bootloader
    
    # In bootloader mode, make again sure the device is recognized
    > fastboot devices
    
    # Flash stock LRX21O recovery image
    > fastboot flash recovery recovery.img
    
    # Flash stock LRX21O system image
    > fastboot flash system system.img
    
    # Flash stock LRX21O boot image
    > fastboot flash boot boot.img
  5. (4?) Reboot your phone, and you’re back to the stock bootloader.

A few things of note: You’ve lost root. All the things that depend on root are now going haywire. That’s ok. We’re not done.

III. Run Android Update

  1. Incessantly check for updates until Android notices. Settings > About Phone > System updates. Sadly, it caches the answer for a good long time, so this may be a “go to bed, try again tomorrow” kinda thing. Especially if you just tried to update and got the android lying on its back.
  2. Run the update. Reboot.
  3. Reboot a few times. Run a few apps. Check for more Android updates (Settings
    > About Phone > System updates). Run these updates too. Make sure the new Android version settled in.

IV. Root it again

Source

  1. Download and unzip CF Auto Root from https://autoroot.chainfire.eu/
  2. Re-enable USB Debugging if it got turned off during the update.
  3. Get into fastboot mode: `adb reboot bootloader`
  4. Run `root-windows.bat` (or the appropriate root for your OS). That gets you root again.
  5. Reboot. It will take a long time to boot. No, it didn’t freeze (unless it’s been hours).
    Feel free to panic, but don’t hard-boot it. If you do brick the phone, start over
    with `II: Put bootloader back to stock` above. No, you didn’t break it.
  6. Once your phone is booted again, update and run SuperSU, Titanium Backup, Android Firewall, BusyBox, and all your other rooted tools.

You’re done. Welcome to the next version of Android.