Skip to content

Instantly share code, notes, and snippets.

@ToniRib
Last active December 20, 2017 17:09
Show Gist options
  • Save ToniRib/40ae899d747a9ecc405a2abf11918e22 to your computer and use it in GitHub Desktop.
Save ToniRib/40ae899d747a9ecc405a2abf11918e22 to your computer and use it in GitHub Desktop.
push build to GitHub & trigger CircleCI build (fish)

Usage: push_build <branch-name:required>

Shell: fish

Pushes the given branch to GitHub, triggers a build on CircleCI, and signs you up for Mac notifications to let you know if the build passed or failed when it is done.

function push_build
  if test (count $argv) -eq 0
    echo "Must include a branch name"
  else
    echo "Pushing and building $1..."
    git push --set-upstream origin $argv[1]
    sleep 0.5
    set trigger_result (circleci trigger gospotcheck/gospotcheck $argv[1])
    set build_num (echo $trigger_result | ruby -e "require 'JSON';json=JSON.parse(STDIN.read); puts json['build_num']")
    echo "Triggered build $build_num"
    circleci notify gospotcheck/gospotcheck $build_num &
  end
end

Prerequisites

$ brew tap rockymadden/rockymadden
$ brew install circleci-cli
$ circleci init
<< paste in a personal API token generated from CircleCI's website under Settings >>
@nickgsc
Copy link

nickgsc commented Dec 20, 2017

This causes major problems if you pass in HEAD as the name of the branch. It doesn't get interpolated to your branch name, resulting in an actual branch named HEAD.

I've opened this issue with the original CLI author, but we need to fix this script to protect against this as well. rockymadden/circleci-cli#53

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment