azure-devops-python-api icon indicating copy to clipboard operation
azure-devops-python-api copied to clipboard

run_pipeline discards needed parameters

Open kenhia opened this issue 5 years ago • 8 comments

azure-devops/azure/devops/v6_0/pipelines/pipelines_client.py takes the parameter run_parameters and then sets the variable content via

        content = self._serialize.body(run_parameters, 'RunPipelineParameters')

In doing so it discards templateParameters (along with previewRun, stagesToSkip, and yamlOverride), but my concern is with templateParameters.

If I'm tracing things correctly, the problem is in the class RunPipelineParameters in azure-devops/azure/devops/v6_0/pipelines/models.py which only maps resources and variables:

class RunPipelineParameters(Model):
    """
    :param resources:
    :type resources: :class:`RunResourcesParameters <azure.devops.v6_0.pipelines.models.RunResourcesParameters>`
    :param variables:
    :type variables: dict
    """

    _attribute_map = {
        'resources': {'key': 'resources', 'type': 'RunResourcesParameters'},
        'variables': {'key': 'variables', 'type': '{Variable}'}
    }

    def __init__(self, resources=None, variables=None):
        super(RunPipelineParameters, self).__init__()
        self.resources = resources
        self.variables = variables

kenhia avatar May 25 '20 16:05 kenhia

I was trying to pass the variables to the run_pipeline function to trigger the pipeline running with specific variables, but failed, any idea for this?

def run_pipeline(self, project, pipe_id):
    variables = RunPipelineParameters(variables={'var_test': 'abc'})
    pipeline_client = self.connection.clients_v6_0.get_pipelines_client()
    pipeline_client.run_pipeline(project=project, pipeline_id=pipe_id, run_parameters=variables)

nallace avatar May 28 '20 07:05 nallace

If I'm reading the what the package is doing correctly, you probably want something more like:

def run_pipe(project, pipe_id):
    run_params = {
        'variables': {
            'var_test': 'abc'
        }
    }
    pipeline_client = self.connection.clients_v6_0.get_pipelines_client()
    pipeline_client.run_pipeline(project=project, pipeline_id=pipe_id, run_parameters=run_params)

But, having dealt with queuing builds/pipelines, you may need the run_params to look like:

def run_pipe(project, pipe_id):
    run_params = {
        'variables': '{"var_test": "abc"}'
    }
    pipeline_client = self.connection.clients_v6_0.get_pipelines_client()
    pipeline_client.run_pipeline(project=project, pipeline_id=pipe_id, run_parameters=run_params)

I'd try the first and see if it works, if not try the second. All the builds I'm playing with currently require templateParameters, so I can't do a quick test. May be able to take some time and set up a test build this weekend and see which way works.

kenhia avatar May 28 '20 23:05 kenhia

Тhis works properly for API Version 6.0-preview.1:

def run_pipe(project, pipe_id):
    run_params = {
        'variables': {
            'var_test':
                {
                    'isSecret': 'false',
                    'value': 'abc'
                }
        }
    }
    pipeline_client = self.connection.clients_v6_0.get_pipelines_client()
    pipeline_client.run_pipeline(project=project, pipeline_id=pipe_id, run_parameters=run_params) 

Request body

variables <string,  Variable>

Variable

Name Type Description
isSecret boolean  
value string

davidljuba15031979 avatar Nov 01 '20 22:11 davidljuba15031979

I think this can be closed as templateParameters are now supported, i.e.

templateParameters={"deployTo": "test"},
run_params = {
            "templateParameters": templateParameters,
            "resources": {
                "repositories": {"self": {"refName": f"refs/heads/{branch_name}"}}
            },
        }

using azure-devops = "^6.0.0-beta.4"

nadworny avatar Oct 21 '21 11:10 nadworny

I think this can be closed as templateParameters are now supported, i.e.

templateParameters={"deployTo": "test"},
run_params = {
            "templateParameters": templateParameters,
            "resources": {
                "repositories": {"self": {"refName": f"refs/heads/{branch_name}"}}
            },
        }

using azure-devops = "^6.0.0-beta.4"

Hi,

Could you please provide an example?

Thanks in advance

anotherancientalien avatar Dec 05 '21 15:12 anotherancientalien

Looks like this was fixed with PR #355 quite some time ago. I'll try it tomorrow and verify that it now supports both template params and variables correctly and post an example and close this issue.

kenhia avatar Dec 05 '21 17:12 kenhia

is there way to set branch??

cant find document of those parm setting

Hanjinchao avatar Feb 21 '23 04:02 Hanjinchao

a way to checkout a specific commit is:

run_params = {
    "resources": {
        "repositories": {
            "self": {
                "refName": "refs/heads/branchName",
                "version": "aeeb82f58eef13a3231fac664355aa68c6b4123be228342306343f1a83e34de3"
            }
        }
    }
}

foremny avatar Jul 21 '23 06:07 foremny