Skip to content

Instantly share code, notes, and snippets.

@erasmas
Last active January 10, 2019 06:29
Show Gist options
  • Save erasmas/315eeb0767a18cf3e737 to your computer and use it in GitHub Desktop.
Save erasmas/315eeb0767a18cf3e737 to your computer and use it in GitHub Desktop.
Setting up build status icon using anybar

Following are the steps to setup a fancy build status icon in your OSX bar using AnyBar. At my current project we use Bamboo for CI, which provides REST API to get build statuses that you can visualize in system bar with green or red icon depending on the state of build.

Install Dependencies

# install cask and anybar
brew install caskroom/cask/brew-cask
brew cask install anybar

# install socat and jq
brew install socat jq

Create script to query Bamboo server

#!/bin/bash

BAMBOO_USER=user
BAMBOO_PASSWORD=password
BAMBOO_URL=https://bamboo.aliceinc.com/rest/api/latest/result/BUILDNAME/latest.json\?buildstate

jq=/usr/local/bin/jq
socat=/usr/local/bin/socat

BUILD_STATUS=`curl -s -u $BAMBOO_USER:$BAMBOO_PASSWORD $BAMBOO_URL | $jq '.buildState'`

ANYBAR_COLOR=`echo $BUILD_STATUS | sed 's/"//g; s/Failed/red/; s/Successful/green/';`

function anybar { echo -n $1 | $socat -t 0 - UDP:localhost:${2:-1738}; }

anybar $ANYBAR_COLOR

Setup launchtl

Create launchctl configuration and save it in $HOME/Library/LaunchAgents/com.aliceinc.BuildMonitor.plist

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
    <dict>
        <key>ExitTimeOut</key>
        <integer>0</integer>
        <key>KeepAlive</key>
        <dict>
            <key>SuccessfulExit</key>
            <true/>
        </dict>

        <key>Label</key>
        <string>com.aliceinc.BuildMonitor</string>

        <key>UserName</key>
        <string>alice</string>

        <key>ProgramArguments</key>
        <array>
            <string>/Users/alice/bin/build-monitor.sh</string>
        </array>

        <key>RunAtLoad</key>
        <true/>

        <key>StartInterval</key>
        <integer>60</integer>

        <key>StandardErrorPath</key>
        <string>/var/log/build-monitor.err</string>

        <key>StandardOutPath</key>
        <string>/var/log/build-monitor.out</string>

    </dict>
</plist>

Start anybar:

open /opt/homebrew-cask/Caskroom/anybar/0.1.3/AnyBar.app/Contents/MacOS/AnyBar

Load launchctl configuration:

launchctl load $HOME/Library/LaunchAgents/com.aliceinc.BuildMonitor.plist
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment