Skip to content

Commit

Permalink
Build branch params
Browse files Browse the repository at this point in the history
* Document build_parameters for Project#build_branch in README
* Add params for Project#build_branch to add revision or parallel
  • Loading branch information
mtchavez committed Jul 29, 2016
1 parent 81da24f commit efa0113
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,18 @@ Build a specific branch of a project
res = CircleCi::Project.build_branch 'username', 'reponame', 'branch'
res.body['status'] # Not running
res.body['build_url'] # Get url of build

# Passing build parameters in the post body
build_params = { build_parameters: { 'MY_TOKEN' => '123asd123asd' } }
res = CircleCi::Project.build_branch 'username', 'reponame', 'branch', {}, build_params
res.body['status'] # Not running
res.body['build_url'] # Get url of build

# Adding URL params for revision or parallel
params = { revision: 'fda12345asdf', parallel: 2 }
res = CircleCi::Project.build_branch 'username', 'reponame', 'branch', params
res.body['status'] # Not running
res.body['build_url'] # Get url of build
```

Example response
Expand Down
4 changes: 2 additions & 2 deletions lib/circleci/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ def self.build(username, project)
# @param branch [String] - Name of branch
# @param body [Hash] - Optional post body with build parameters
# @return [CircleCi::Response] - Response object
def self.build_branch(username, project, branch, body = {})
CircleCi.request("/project/#{username}/#{project}/tree/#{branch}").post(body)
def self.build_branch(username, project, branch, params = {}, body = {})
CircleCi.request("/project/#{username}/#{project}/tree/#{branch}", params).post(body)
end

##
Expand Down
2 changes: 1 addition & 1 deletion spec/circleci/project_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
end

context 'experimental api' do
let(:res) { described_class.build_branch 'mtchavez', 'circleci', 'master', 'SOME_VAR' => '123' }
let(:res) { described_class.build_branch 'mtchavez', 'circleci', 'master', {}, 'SOME_VAR' => '123' }

it 'is verified by response' do
expect(res).to be_instance_of(CircleCi::Response)
Expand Down

0 comments on commit efa0113

Please sign in to comment.