[Python] How to pass parameter to azure pipeline using python script, API

Discussão em 'Python' iniciado por Stack, Fevereiro 13, 2025.

  1. Stack

    Stack Membro Participativo

    I have a script in python which triggers pipeline build using API. I need to figure out how to pass parameter to this pipeline.

    this script below runs pipeline with id 3023 and returns status 200:

    def run_pipeline(PAT):
    url="[organization_url]_apis/pipelines/[pipeline_id]/runs?api-version=6.0-preview.1"
    headers = {"Content-Type": "application/json; charset=utf-8"}
    data={
    'id': '3023'
    }
    request_run_pipeline = requests.post(url, headers=headers, json=data, auth = ('',PAT),verify = False)

    return(print(request_run_pipeline.status_code))


    now, my test pipeline with a parameter looks like this:

    parameters:
    - name: text
    type: string
    default: test pipeline

    trigger:
    branches:
    include:
    - main

    steps:
    - script: echo ${{ parameters.text }}
    displayName: 'run one-line script - write text'


    I need to somehow pass this "text" parameter using my python script, no idea how to do it.

    Continue reading...

Compartilhe esta Página