Skip to content

Commit d049491

Browse files
Dmitriy DiachkovDmitriy Diachkov
authored andcommitted
Added methods for creating a branch, enabling it and executing plan
1 parent c863d85 commit d049491

File tree

1 file changed

+56
-1
lines changed

1 file changed

+56
-1
lines changed

atlassian/bamboo.py

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,61 @@ def plan_branches(self, plan_key, expand=None, favourite=False, clover_enabled=F
351351
return self.base_list_call(resource, expand, favourite, clover_enabled, max_results,
352352
elements_key='branches', element_key='branch')
353353

354+
def create_branch(self, plan_key, branch_name, vcs_branch=None, enabled=False, cleanup_enabled=False):
355+
"""
356+
Method for creating branch for a specified plan.
357+
You can use vcsBranch query param to define which vcsBranch should newly created branch use.
358+
If not specified it will not override vcsBranch from the main plan.
359+
360+
:param plan_key: str TST-BLD
361+
:param branch_name: str new-shiny-branch
362+
:param vcs_branch: str feature/new-shiny-branch, /refs/heads/new-shiny-branch
363+
:param enabled: bool
364+
:param cleanup_enabled: bool
365+
:return: PUT request
366+
"""
367+
resource = 'plan/{plan_key}/branch/{branch_name}'.format(plan_key=plan_key, branch_name=branch_name)
368+
if vcs_branch:
369+
resource += '?vcsBranch{vcs_branch}'.format(vcs_branch=vcs_branch)
370+
resource += '&enabled={}'.format('true' if enabled else 'false')
371+
resource += '&cleanupEnabled={}'.format('true' if cleanup_enabled else 'false')
372+
return self.put(self.resource_url(resource))
373+
374+
def enable_plan(self, plan_key):
375+
"""
376+
Enable plan.
377+
:param plan_key: str TST-BLD
378+
:return: POST request
379+
"""
380+
resource = 'plan/{plan_key}/enable'.format(plan_key=plan_key)
381+
return self.post(self.resource_url(resource))
382+
383+
def execute_build(self, plan_key, stage=None, executeAllStages=True, customRevision=None, **bamboo_variables):
384+
"""
385+
Fire build execution for specified plan.
386+
!IMPORTANT! NOTE: for some reason, this method always execute all stages
387+
:param plan_key: str TST-BLD
388+
:param stage: str stage-name
389+
:param executeAllStages: bool
390+
:param customRevision: str revisionName
391+
:param bamboo_variables: dict {variable=value}
392+
:return: POST request
393+
"""
394+
headers = self.form_token_headers
395+
resource = 'queue/{plan_key}'.format(plan_key=plan_key)
396+
params = {}
397+
if stage:
398+
executeAllStages = False
399+
params['stage'] = stage
400+
if customRevision:
401+
params['customRevision'] = customRevision
402+
params['executeAllStages'] = 'true' if executeAllStages else 'false'
403+
if bamboo_variables:
404+
for key, value in bamboo_variables.items():
405+
params['bamboo.variable.{}'.format(key)] = value
406+
407+
return self.post(self.resource_url(resource), params=params, headers=headers)
408+
354409
def health_check(self):
355410
"""
356411
Get health status
@@ -489,4 +544,4 @@ def upload_plugin(self, plugin_path):
489544
upm_token = self.request(method='GET', path='rest/plugins/1.0/', headers=headers, trailing=True).headers[
490545
'upm-token']
491546
url = 'rest/plugins/1.0/?token={upm_token}'.format(upm_token=upm_token)
492-
return self.post(url, files=files, headers=headers)
547+
return self.post(url, files=files, headers=headers)

0 commit comments

Comments
 (0)