Skip to content

Instantly share code, notes, and snippets.

@masonmark
Created April 4, 2017 10:12
Show Gist options
  • Save masonmark/9b68f0b291c7daae74b770538ab699f8 to your computer and use it in GitHub Desktop.
Save masonmark/9b68f0b291c7daae74b770538ab699f8 to your computer and use it in GitHub Desktop.
A script to trigger a CircleCI 2.0 build without actually committing and pushing to GitHub
#!/usr/bin/env ruby
# This script is for when you are tweaking the .circleci/config.yml file itself, and don't
# want to have to actually push a bunch of changes to the project master repo each
# time you want to test a change to the config. (Using this will also reduce spam from any
# bots that might be watching for git spam, and so on...)
#
# Adapted from: https://discuss.circleci.com/t/efficiently-testing-configuration-file-migrating-to-2-0/11620/2
#
# Assuming a project using GitHub, running this file will trigger CircleCI (2.0 platform) without
# actually pushing to the project repo. (I save it as ./bin/run_circle_ci.rb; paths may need to be
# updated for other projects/configurations.)
require 'pathname'
PATH_TO_ME = Pathname.new File.expand_path(__FILE__)
PATH_TO_ROOT = PATH_TO_ME.parent.parent
Dir.chdir PATH_TO_ROOT
github_organization = 'MyCoolCompany'
github_project = 'my-stupendous-project'
circle_ci_api_token = 'deadbeef1234decafbad6789f0f0f0f0f0f0f0f0'
existing_git_sha = "feedface91123456789e0e0e0e0e0e0e0e0e0e0e"
existing_git_branch = "my-branch-name"
# Note: the branch must exist, but the commit identified by existing_git_sha
# does not actually have to be in the commit.
cmd = [
"curl --user #{circle_ci_api_token}:",
"--request POST",
"--form revision=#{existing_git_sha}",
"--form [email protected]/config.yml",
"--form notify=false",
"https://circleci.com/api/v1.1/project/github/#{github_organization}/#{github_project}/tree/#{existing_git_branch}"
].join(' ')
puts ''
puts '➡️ ' + cmd
puts ''
Kernel.exec cmd
# FIXME: might be nice to not use Kernel.exec above, instead capture the output (which contains a JSON struct including the build number), and then open the build's specific URL:
# https://circleci.com/gh/#{github_organization}/#{github_project}/#{build_number}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment