This article describes how to customize building, testing, packaging, and delivering Python apps and code in Azure Pipelines. To create your first pipeline with Python, see the Python quickstart.
With Microsoft-hosted agents in Azure Pipelines, you can build your Python apps without having to set up your own infrastructure. Tools that you commonly use to build, test, and run Python apps, including pip, are preinstalled.
To build Python apps with Azure Pipelines, you need a self-hosted agent with Python installed. To install Python on your agent, see UsePythonVersion.
Use a specific Python version
To use a specific version of Python in your pipeline, add the Use Python version task to azure-pipelines.yml. The following example YAML pipeline definition sets the pipeline to use Python 3.11.
To run a pipeline with multiple Python versions, for example to test a package against those versions, define a job with a matrix of Python versions. Then set the UsePythonVersion task to reference the matrix variable. For example:
- task:PythonScript@0 inputs: scriptSource:'inline' script:|
print('Hello world 1')
print('Hello world 2')
To parameterize script execution, use the PythonScript task with arguments values to pass arguments into the running process. You can use sys.argv or the more sophisticated argparse library to parse the arguments.
YAML
- task:PythonScript@0 inputs: scriptSource:inline script:|
import sys
print ('Executing script file is:', str(sys.argv[0]))
print ('The arguments are:', str(sys.argv))
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("--world", help="Provide the name of the world to greet.")
args = parser.parse_args()
print ('Hello ', args.world)
arguments:--worldVenus
Install dependencies
You can use scripts to install specific PyPI packages with pip. The following example installs or upgrades pip and the setuptools and wheel packages.
Test with pytest and collect coverage metrics with pytest-cov
The following YAML code installs pytest and pytest-cov and runs tests, outputting test results in JUnit format and outputting code coverage results in Cobertura XML format.
Azure Pipelines can run parallel Tox test jobs to split up the work. On a development computer, you have to run your test environments in series. The following example uses tox -e py to run whichever version of Python is active for the current job.
- task:PublishTestResults@2 condition:succeededOrFailed() inputs: testResultsFiles:'**/test-*.xml' testRunTitle:'Publish test results for Python $(python.version)'
Publish code coverage results
Add the Publish code coverage results task to publish code coverage results to the server. You can see coverage metrics in the build summary, and download HTML reports for further analysis.
Pievienojieties meetup sērijai, lai kopā ar citiem izstrādātājiem un ekspertiem izveidotu mērogojamus AI risinājumus, kuru pamatā ir reālas lietošanas gadījumi.
In this learning path, find out how to collaborate with others to continuously build, test, and verify your applications using Azure Pipelines and GitHub.
Manage data ingestion and preparation, model training and deployment, and machine learning solution monitoring with Python, Azure Machine Learning and MLflow.
Carlton Gibson, Django Software Fellow and Django maintainer, is again talking to Nina Zakharenko about using Python and Django. In this episode, Carlton will show how you can use Azure Pipelines (part of Azure DevOps) to enable Continuous Integration and Continuous Delivery (CI/CD) of Python/Django apps to Azure Web Apps (or anywhere else!).PS Did you know that Azure DevOps is free for individuals and small teams up to five, and it includes unlimited, private Git repos?Jump To: [00:50] Demo Start