Skip to content

Commit

Permalink
Pipeline create command should have an option to skip the first run (#…
Browse files Browse the repository at this point in the history
…741)

* Pipeline create command should have an option to skip the first run

* Add alias as --skip-run
  • Loading branch information
atbagga committed Aug 2, 2019
1 parent 3c5d20a commit 79d977f
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 4 deletions.
11 changes: 11 additions & 0 deletions azure-devops/azext_devops/dev/pipelines/_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,17 @@ def transform_pipeline_runs_table_output(result):
return table_output


def transform_pipeline_or_run_table_output(result):
table_output = [_transform_pipeline_or_run_row(result)]
return table_output


def _transform_pipeline_or_run_row(row):
if row.get("buildNumber", None): # Hack to detect the json object is definition or run
return _transform_pipeline_run_row(row)
return _transform_pipeline_row(row)


def transform_pipeline_run_table_output(result):
table_output = [_transform_pipeline_run_row(result)]
return table_output
Expand Down
2 changes: 2 additions & 0 deletions azure-devops/azext_devops/dev/pipelines/arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ def load_build_arguments(self, _):
with self.argument_context('pipelines create') as context:
context.argument('repository_type', choices=['tfsgit', 'github'], type=str.lower)
context.argument('yml_path', options_list=('--yml-path', '--yaml-path'))
context.argument('skip_first_run', options_list=['--skip-first-run', '--skip-run'],
arg_type=get_three_state_flag())

with self.argument_context('pipelines update') as context:
context.argument('yml_path', options_list=('--yml-path', '--yaml-path'))
Expand Down
3 changes: 2 additions & 1 deletion azure-devops/azext_devops/dev/pipelines/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from ._format import (transform_build_table_output,
transform_builds_table_output,
transform_pipeline_run_table_output,
transform_pipeline_or_run_table_output,
transform_pipeline_runs_table_output,
transform_pipeline_table_output,
transform_pipelines_table_output,
Expand Down Expand Up @@ -94,7 +95,7 @@
# pylint: disable=too-many-statements
def load_build_commands(self, _):
with self.command_group('pipelines', command_type=pipelineCreateOps) as g:
g.command('create', 'pipeline_create', table_transformer=transform_pipeline_run_table_output)
g.command('create', 'pipeline_create', table_transformer=transform_pipeline_or_run_table_output)
g.command('update', 'pipeline_update', table_transformer=transform_pipeline_table_output)

with self.command_group('pipelines', command_type=pipelinesOps) as g:
Expand Down
13 changes: 10 additions & 3 deletions azure-devops/azext_devops/dev/pipelines/pipeline_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,10 @@ def __init__(self, name, id, content, description='Custom yaml', params=None, pa
_AZURE_GIT_REPO_TYPE = 'tfsgit'


# pylint: disable=too-many-statements
def pipeline_create(name, description=None, repository=None, branch=None, yml_path=None, repository_type=None,
service_connection=None, organization=None, project=None, detect=None, queue_id=None):
service_connection=None, organization=None, project=None, detect=None, queue_id=None,
skip_first_run=None):
""" (PREVIEW) Create a new Azure Pipeline (YAML based)
:param name: Name of the new pipeline
:type name: str
Expand All @@ -71,6 +73,9 @@ def pipeline_create(name, description=None, repository=None, branch=None, yml_pa
:type service_connection: str
:param queue_id: Id of the queue in the available agent pools. Will be auto detected if not specified.
:type queue_id: str
:param skip_first_run: Specify this flag to prevent the first run being triggered by the command.
Command will return a pipeline if run is skipped else it will output a pipeline run.
:type skip_first_run: bool
"""
repository_name = None
if repository:
Expand Down Expand Up @@ -140,8 +145,10 @@ def pipeline_create(name, description=None, repository=None, branch=None, yml_pa
created_definition = client.create_definition(definition=definition, project=project)
logger.warning('Successfully created a pipeline with Name: %s, Id: %s.',
created_definition.name, created_definition.id)
return client.queue_build(
build=Build(definition=created_definition, source_branch=queue_branch), project=project)
if skip_first_run:
return created_definition
return client.queue_build(build=Build(definition=created_definition, source_branch=queue_branch),
project=project)


def pipeline_update(name=None, id=None, description=None, new_name=None, # pylint: disable=redefined-builtin
Expand Down

0 comments on commit 79d977f

Please sign in to comment.