Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pipeline client 6.0 added to support template parameters for pipelines runs #1211

Merged
merged 63 commits into from
Nov 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
2dba759
Adding example for multiple fields command
Jul 2, 2021
782fb6f
Duplicate dependencies removed
Jul 15, 2021
5b6fd42
Internal changes
Jul 15, 2021
ed4c075
Pipeline changes
Jul 19, 2021
224c0c2
Merge branch 'master' into Internal
Jul 20, 2021
3d95e61
Warning messages added for ADO server
Jul 20, 2021
6d5bacf
Strip the trailing slash
Jul 20, 2021
dd0cbff
run style chagnes
Jul 20, 2021
406b6ad
Merge branch 'Users/Roshan/1151' into Internal
Jul 20, 2021
bcb6c39
Test cases changes
Jul 22, 2021
f1910e8
1132
Aug 2, 2021
f7dac16
Merge branch 'master' into Internal
Aug 2, 2021
a520655
1132 chnages
Aug 3, 2021
e9d9b9a
Fixed: Made object id optional
Aug 3, 2021
9847e21
Comment changes
Aug 3, 2021
5325b69
Merge branch 'Users/Roshan/1132' into Internal
Aug 3, 2021
6de84e9
run style changes
Aug 3, 2021
4955cd0
Merge branch 'master' into Users/Roshan/1132
Aug 4, 2021
472df75
Merge branch 'Users/Roshan/1132' into Internal
Aug 4, 2021
684d580
dlete
Aug 4, 2021
bde24ae
show_command
Aug 4, 2021
55fa5ce
Merge branch 'master' into Internal
Aug 13, 2021
75c7310
internal
Aug 24, 2021
889daf3
1174
Aug 25, 2021
19d770f
sleep_in_live_run = 60
Aug 25, 2021
b98dbc5
sleep time changed for all
Aug 25, 2021
ae0c002
Merge branch 'master' into User/Roshan/Internal
roshan-sy Sep 15, 2021
ceb4240
Merge branch 'master' into User/Roshan/Internal
roshan-sy Sep 20, 2021
1d4b53d
Fixed
roshan-sy Sep 20, 2021
d689b54
None checked
roshan-sy Sep 20, 2021
dacddce
reviewers none checked
roshan-sy Sep 20, 2021
2966e64
Merge branch 'Users/Roshan/1118' into User/Roshan/Internal
roshan-sy Sep 21, 2021
951db17
Changes for new pipeline client
roshan-sy Oct 6, 2021
f82b170
Refactor
roshan-sy Oct 6, 2021
02f5e51
launch reset
roshan-sy Oct 7, 2021
ce428f4
Reset
roshan-sy Oct 7, 2021
c1e2028
Reset 2
roshan-sy Oct 7, 2021
05b4135
Run style changes
roshan-sy Oct 7, 2021
cd64358
Run style fix
roshan-sy Oct 7, 2021
896b9bd
Merge branch 'master' into Users/Roshan/1110-2
roshan-sy Oct 29, 2021
3540051
Pipeline run test cases added
roshan-sy Nov 3, 2021
34c097b
run style fix
roshan-sy Nov 3, 2021
3438b6b
Run style fixed
roshan-sy Nov 3, 2021
0e868ad
parameters changes
roshan-sy Nov 5, 2021
2dadb03
set_param_variable function
Nov 5, 2021
9165e7a
Pipeline.py
Nov 8, 2021
2de5891
Merge branch 'master' into Users/Roshan/1110-2
roshan-sy Nov 9, 2021
5b2f5a3
Convert_param changes
Nov 10, 2021
6ccf941
Merge branch 'Users/Roshan/1110-2' of https://github.com/Microsoft/az…
Nov 10, 2021
ceffe26
Fixes
roshan-sy Nov 10, 2021
e1c730e
Run style changes
roshan-sy Nov 10, 2021
534bf6f
Run style changes
roshan-sy Nov 10, 2021
dcc0e0f
Deleted convert_param
Nov 12, 2021
bf3576f
Merge branch 'Users/Roshan/1110-2' of https://github.com/Microsoft/az…
Nov 12, 2021
9ecac49
Test Fix
roshan-sy Nov 12, 2021
beb04ba
Merge remote-tracking branch 'origin/master' into Users/Roshan/1110-2
roshan-sy Nov 12, 2021
8cb350b
Run style changes
roshan-sy Nov 12, 2021
4fdd38f
pythonPath fix
roshan-sy Nov 12, 2021
68d4d8c
error text validation
Nov 12, 2021
181cfc3
Merge branch 'Users/Roshan/1110-2' of https://github.com/Microsoft/az…
Nov 12, 2021
a0a6553
Run style fixed
roshan-sy Nov 12, 2021
04d86a9
logg added
roshan-sy Nov 12, 2021
9d5ac40
parameter type changed to array
roshan-sy Nov 12, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions azure-devops/azext_devops/dev/common/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,11 @@ def get_new_pipeline_client(organization=None):
return connection.get_client(VSTS_MODULE + 'v5_1.build.build_client.BuildClient')


def get_new_pipeline_client_v60(organization=None):
connection = get_connection(organization)
return connection.get_client(VSTS_MODULE + 'v6_0.pipelines.pipelines_client.PipelinesClient')


def get_new_task_agent_client(organization=None):
connection = get_connection(organization)
return connection.get_client(VSTS_MODULE + 'v5_1.task_agent.task_agent_client.TaskAgentClient')
Expand Down
1 change: 1 addition & 0 deletions azure-devops/azext_devops/dev/pipelines/arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ def load_build_arguments(self, _):

with self.argument_context('pipelines run') as context:
context.argument('id', type=int)
context.argument('parameters', nargs='*')
context.argument('variables', nargs='*')

with self.argument_context('pipelines list') as context:
Expand Down
61 changes: 50 additions & 11 deletions azure-devops/azext_devops/dev/pipelines/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,17 @@
from knack.util import CLIError
from azext_devops.dev.common.services import (get_build_client,
get_git_client,
resolve_instance_and_project)
resolve_instance_and_project,
get_new_pipeline_client_v60)
from azext_devops.dev.common.uri import uri_quote
from azext_devops.dev.common.uuid import is_uuid
from azext_devops.dev.common.git import resolve_git_ref_heads
from azext_devops.devops_sdk.v5_0.build.models import Build, DefinitionReference
from azext_devops.devops_sdk.v6_0.pipelines.models import (RunPipelineParameters,
RunResourcesParameters,
RepositoryResourceParameters)
from .build_definition import get_definition_id_from_name, fix_path_for_api
from .pipeline_run import _open_pipeline_run
from .pipeline_run import _open_pipeline_run, _open_pipeline_run6_0

logger = get_logger(__name__)

Expand Down Expand Up @@ -96,8 +100,25 @@ def pipeline_show(id=None, name=None, open=False, organization=None, project=Non
return build_definition


def set_param_variable(variables, as_dict=False, argument='variables'):
param_variables = None
if variables is not None and variables:
param_variables = {}
for variable in variables:
separator_pos = variable.find('=')
if separator_pos >= 0:
if as_dict:
param_variables[variable[:separator_pos]] = {"value": variable[separator_pos + 1:]}
else:
param_variables[variable[:separator_pos]] = variable[separator_pos + 1:]
else:
raise ValueError(
f'The --{argument} argument should consist of space separated "name=value" pairs.')
roshan-sy marked this conversation as resolved.
Show resolved Hide resolved
return param_variables


def pipeline_run(id=None, branch=None, commit_id=None, name=None, open=False, variables=None, # pylint: disable=redefined-builtin
folder_path=None, organization=None, project=None, detect=None):
folder_path=None, organization=None, project=None, detect=None, parameters=None):
""" Queue (run) a pipeline.
:param id: ID of the pipeline to queue. Required if --name is not supplied.
:type id: int
Expand All @@ -110,6 +131,8 @@ def pipeline_run(id=None, branch=None, commit_id=None, name=None, open=False, va
:type folder_path: str
:param variables: Space separated "name=value" pairs for the variables you would like to set.
:type variables: [str]
:param parameters: Space separated "name=value" pairs for the parameters you would like to set.
:type parameters: [str]
:param commit_id: Commit-id on which the pipeline run is to be queued.
:type commit_id: str
:param open: Open the pipeline results page in your web browser.
Expand All @@ -123,20 +146,36 @@ def pipeline_run(id=None, branch=None, commit_id=None, name=None, open=False, va
raise ValueError('Either the --id argument or the --name argument ' +
'must be supplied for this command.')
client = get_build_client(organization)

if id is None:
id = get_definition_id_from_name(name, client, project, folder_path)

if parameters:
logger.debug('Using "pipelines client v6_0" to include parameters in run')
client = get_new_pipeline_client_v60(organization)
roshan-sy marked this conversation as resolved.
Show resolved Hide resolved

repositories = {"self": RepositoryResourceParameters(ref_name=branch, version=commit_id)}
resources = RunResourcesParameters(repositories=repositories)
template_parameters = set_param_variable(parameters, argument='parameters')

param_variables = set_param_variable(variables, as_dict=True)
run_parameters = RunPipelineParameters(
resources=resources, variables=param_variables, template_parameters=template_parameters)

queued_pipeline = client.run_pipeline(run_parameters=run_parameters, project=project, pipeline_id=id)
if open:
_open_pipeline_run6_0(queued_pipeline, project, organization)
return queued_pipeline

definition_reference = DefinitionReference(id=id)
branch = resolve_git_ref_heads(branch)
build = Build(definition=definition_reference, source_branch=branch, source_version=commit_id)
if variables is not None and variables:
build.parameters = {}
for variable in variables:
separator_pos = variable.find('=')
if separator_pos >= 0:
build.parameters[variable[:separator_pos]] = variable[separator_pos + 1:]
else:
raise ValueError('The --variables argument should consist of space separated "name=value" pairs.')

param_variables = set_param_variable(variables)
build.parameters = param_variables

queued_build = client.queue_build(build=build, project=project)

if open:
_open_pipeline_run(queued_build, organization)
return queued_build
Expand Down
13 changes: 13 additions & 0 deletions azure-devops/azext_devops/dev/pipelines/pipeline_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,3 +152,16 @@ def _open_pipeline_run(run, organization):
+ uri_quote(str(run.id))
logger.debug('Opening web page: %s', url)
open_new(url=url)


def _open_pipeline_run6_0(run, project, organization):
"""Open the build results page in your web browser.
:param :class:`<Run> <azure.devops.v6_0.pipelines.models.Run>`
:param str project:
:param str organization:
"""
from webbrowser import open_new
from azext_devops.dev.common.uri import uri_quote
url = f"{organization.rstrip('/')}/{uri_quote(project)}/_build/results?buildid={uri_quote(str(run.id))}"
logger.debug('Opening web page: %s', url)
open_new(url=url)
7 changes: 7 additions & 0 deletions azure-devops/azext_devops/devops_sdk/v6_0/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------
# Generated file, DO NOT EDIT
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
# --------------------------------------------------------------------------------------------
17 changes: 17 additions & 0 deletions azure-devops/azext_devops/devops_sdk/v6_0/accounts/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------
# Generated file, DO NOT EDIT
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
# --------------------------------------------------------------------------------------------

from .models import *
from .accounts_client import AccountsClient

__all__ = [
'Account',
'AccountCreateInfoInternal',
'AccountPreferencesInternal',
'AccountsClient'
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------
# Generated file, DO NOT EDIT
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
# --------------------------------------------------------------------------------------------

from msrest import Serializer, Deserializer
from ...client import Client
from . import models


class AccountsClient(Client):
"""Accounts
:param str base_url: Service URL
:param Authentication creds: Authenticated credentials.
"""

def __init__(self, base_url=None, creds=None):
super(AccountsClient, self).__init__(base_url, creds)
client_models = {k: v for k, v in models.__dict__.items() if isinstance(v, type)}
self._serialize = Serializer(client_models)
self._deserialize = Deserializer(client_models)

resource_area_identifier = '0d55247a-1c47-4462-9b1f-5e2125590ee6'

def get_accounts(self, owner_id=None, member_id=None, properties=None):
"""GetAccounts.
[Preview API] Get a list of accounts for a specific owner or a specific member. One of the following parameters is required: ownerId, memberId.
:param str owner_id: ID for the owner of the accounts.
:param str member_id: ID for a member of the accounts.
:param str properties:
:rtype: [Account]
"""
query_parameters = {}
if owner_id is not None:
query_parameters['ownerId'] = self._serialize.query('owner_id', owner_id, 'str')
if member_id is not None:
query_parameters['memberId'] = self._serialize.query('member_id', member_id, 'str')
if properties is not None:
query_parameters['properties'] = self._serialize.query('properties', properties, 'str')
response = self._send(http_method='GET',
location_id='229a6a53-b428-4ffb-a835-e8f36b5b4b1e',
version='6.0-preview.1',
query_parameters=query_parameters)
return self._deserialize('[Account]', self._unwrap_collection(response))

149 changes: 149 additions & 0 deletions azure-devops/azext_devops/devops_sdk/v6_0/accounts/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------
# Generated file, DO NOT EDIT
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
# --------------------------------------------------------------------------------------------

from msrest.serialization import Model


class Account(Model):
"""
:param account_id: Identifier for an Account
:type account_id: str
:param account_name: Name for an account
:type account_name: str
:param account_owner: Owner of account
:type account_owner: str
:param account_status: Current account status
:type account_status: object
:param account_type: Type of account: Personal, Organization
:type account_type: object
:param account_uri: Uri for an account
:type account_uri: str
:param created_by: Who created the account
:type created_by: str
:param created_date: Date account was created
:type created_date: datetime
:param has_moved:
:type has_moved: bool
:param last_updated_by: Identity of last person to update the account
:type last_updated_by: str
:param last_updated_date: Date account was last updated
:type last_updated_date: datetime
:param namespace_id: Namespace for an account
:type namespace_id: str
:param new_collection_id:
:type new_collection_id: str
:param organization_name: Organization that created the account
:type organization_name: str
:param properties: Extended properties
:type properties: :class:`object <azure.devops.v6_0.accounts.models.object>`
:param status_reason: Reason for current status
:type status_reason: str
"""

_attribute_map = {
'account_id': {'key': 'accountId', 'type': 'str'},
'account_name': {'key': 'accountName', 'type': 'str'},
'account_owner': {'key': 'accountOwner', 'type': 'str'},
'account_status': {'key': 'accountStatus', 'type': 'object'},
'account_type': {'key': 'accountType', 'type': 'object'},
'account_uri': {'key': 'accountUri', 'type': 'str'},
'created_by': {'key': 'createdBy', 'type': 'str'},
'created_date': {'key': 'createdDate', 'type': 'iso-8601'},
'has_moved': {'key': 'hasMoved', 'type': 'bool'},
'last_updated_by': {'key': 'lastUpdatedBy', 'type': 'str'},
'last_updated_date': {'key': 'lastUpdatedDate', 'type': 'iso-8601'},
'namespace_id': {'key': 'namespaceId', 'type': 'str'},
'new_collection_id': {'key': 'newCollectionId', 'type': 'str'},
'organization_name': {'key': 'organizationName', 'type': 'str'},
'properties': {'key': 'properties', 'type': 'object'},
'status_reason': {'key': 'statusReason', 'type': 'str'}
}

def __init__(self, account_id=None, account_name=None, account_owner=None, account_status=None, account_type=None, account_uri=None, created_by=None, created_date=None, has_moved=None, last_updated_by=None, last_updated_date=None, namespace_id=None, new_collection_id=None, organization_name=None, properties=None, status_reason=None):
super(Account, self).__init__()
self.account_id = account_id
self.account_name = account_name
self.account_owner = account_owner
self.account_status = account_status
self.account_type = account_type
self.account_uri = account_uri
self.created_by = created_by
self.created_date = created_date
self.has_moved = has_moved
self.last_updated_by = last_updated_by
self.last_updated_date = last_updated_date
self.namespace_id = namespace_id
self.new_collection_id = new_collection_id
self.organization_name = organization_name
self.properties = properties
self.status_reason = status_reason


class AccountCreateInfoInternal(Model):
"""
:param account_name:
:type account_name: str
:param creator:
:type creator: str
:param organization:
:type organization: str
:param preferences:
:type preferences: :class:`AccountPreferencesInternal <azure.devops.v6_0.accounts.models.AccountPreferencesInternal>`
:param properties:
:type properties: :class:`object <azure.devops.v6_0.accounts.models.object>`
:param service_definitions:
:type service_definitions: list of { key: str; value: str }
"""

_attribute_map = {
'account_name': {'key': 'accountName', 'type': 'str'},
'creator': {'key': 'creator', 'type': 'str'},
'organization': {'key': 'organization', 'type': 'str'},
'preferences': {'key': 'preferences', 'type': 'AccountPreferencesInternal'},
'properties': {'key': 'properties', 'type': 'object'},
'service_definitions': {'key': 'serviceDefinitions', 'type': '[{ key: str; value: str }]'}
}

def __init__(self, account_name=None, creator=None, organization=None, preferences=None, properties=None, service_definitions=None):
super(AccountCreateInfoInternal, self).__init__()
self.account_name = account_name
self.creator = creator
self.organization = organization
self.preferences = preferences
self.properties = properties
self.service_definitions = service_definitions


class AccountPreferencesInternal(Model):
"""
:param culture:
:type culture: object
:param language:
:type language: object
:param time_zone:
:type time_zone: object
"""

_attribute_map = {
'culture': {'key': 'culture', 'type': 'object'},
'language': {'key': 'language', 'type': 'object'},
'time_zone': {'key': 'timeZone', 'type': 'object'}
}

def __init__(self, culture=None, language=None, time_zone=None):
super(AccountPreferencesInternal, self).__init__()
self.culture = culture
self.language = language
self.time_zone = time_zone


__all__ = [
'Account',
'AccountCreateInfoInternal',
'AccountPreferencesInternal',
]
19 changes: 19 additions & 0 deletions azure-devops/azext_devops/devops_sdk/v6_0/audit/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------
# Generated file, DO NOT EDIT
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
# --------------------------------------------------------------------------------------------

from .models import *
from .audit_client import AuditClient

__all__ = [
'AuditActionInfo',
'AuditLogEntry',
'AuditLogQueryResult',
'AuditStream',
'DecoratedAuditLogEntry',
'AuditClient'
]
Loading