Skip to content

Latest commit

 

History

History
238 lines (191 loc) · 7.29 KB

python-script-v0.md

File metadata and controls

238 lines (191 loc) · 7.29 KB
title description ms.date monikerRange
PythonScript@0 - Python script v0 task
Run a Python file or inline script.
08/27/2024
>=azure-pipelines-2019

PythonScript@0 - Python script v0 task

:::moniker range=">=azure-pipelines-2019"

Use this task to run a Python file or inline script.

:::moniker-end

Syntax

:::moniker range=">=azure-pipelines-2019.1"

# Python script v0
# Run a Python file or inline script.
- task: PythonScript@0
  inputs:
    scriptSource: 'filePath' # 'filePath' | 'inline'. Required. Script source. Default: filePath.
    scriptPath: # string. Required when scriptSource = filePath. Script path. 
    #script: # string. Required when scriptSource = inline. Script. 
    #arguments: # string. Arguments. 
  # Advanced
    #pythonInterpreter: # string. Python interpreter. 
    #workingDirectory: # string. Working directory. 
    #failOnStderr: false # boolean. Fail on standard error. Default: false.

:::moniker-end

:::moniker range="=azure-pipelines-2019"

# Python Script v0
# Run a Python script.
- task: PythonScript@0
  inputs:
    scriptSource: 'filePath' # 'filePath' | 'inline'. Required. Script source. Default: filePath.
    scriptPath: # string. Required when scriptSource = filePath. Script path. 
    #script: # string. Required when scriptSource = inline. Script. 
    #arguments: # string. Arguments. 
  # Advanced
    #pythonInterpreter: # string. Python interpreter. 
    #workingDirectory: # string. Working directory. 
    #failOnStderr: false # boolean. Fail on standard error. Default: false.

:::moniker-end

Inputs

:::moniker range=">=azure-pipelines-2019"

scriptSource - Script source
string. Required. Allowed values: filePath (File path), inline. Default value: filePath.

Specifies whether the script is a file in the source tree or is written inline in this task.


:::moniker-end

:::moniker range=">=azure-pipelines-2019"

scriptPath - Script path
string. Required when scriptSource = filePath.

Specifies the path of the script to execute. Must be a fully qualified path or relative to $(System.DefaultWorkingDirectory).


:::moniker-end

:::moniker range=">=azure-pipelines-2019"

script - Script
string. Required when scriptSource = inline.

Specifies the Python script to run.


:::moniker-end

:::moniker range=">=azure-pipelines-2019"

arguments - Arguments
string.

Specifies the arguments passed to the script execution available through sys.argv, as if you passed them on the command line.


:::moniker-end

:::moniker range=">=azure-pipelines-2019"

pythonInterpreter - Python interpreter
string.

Specifies the absolute path to the Python interpreter to use. If not specified, the task will use the interpreter in PATH.
Run the Use Python Version task to add a version of Python to PATH.


:::moniker-end

:::moniker range=">=azure-pipelines-2019"

workingDirectory - Working directory
string.

Specifies the working directory where the script will run. If not specified, the value of System.DefaultWorkingDirectory will be used. For builds, this variable defaults to the root of the repository. For releases, it defaults to the root of the artifacts directory.


:::moniker-end

:::moniker range=">=azure-pipelines-2019"

failOnStderr - Fail on standard error
boolean. Default value: false.

If set to true, this task will fail if any text is written to the stderr stream.


:::moniker-end

Task control options

All tasks have control options in addition to their task inputs. For more information, see Control options and common task properties.

Output variables

:::moniker range=">=azure-pipelines-2019"

None.

:::moniker-end

Remarks

By default, this task will invoke python from the system path. Run Use Python Version to put the version you want in the system path.

Examples

Run an inline Python script.

- task: PythonScript@0
  inputs:
    scriptSource: 'inline'
    script: |
      print('Hello world 1')
      print('Hello world 2')

Run an inline Python script that uses an environment variable.

- task: PythonScript@0
  inputs:
    scriptSource: 'inline'
    script: |
      import os
      print(f'Environment variable MY_VAR: {os.getenv("MY_VAR")}')
  env:
    MY_VAR: 'Hello, World!'

Run a Python script from the working directory. The task will fail if any text is written to the stderr stream.

- task: PythonScript@0
  inputs:
    scriptSource: 'filePath'
    scriptPath: 'scripts/hello_world.py'
    workingDirectory: '$(Build.SourcesDirectory)/scripts'
    failOnStderr: true

Requirements

:::moniker range=">=azure-pipelines-2019"

Requirement Description
Pipeline types YAML, Classic build, Classic release
Runs on Agent, DeploymentGroup
Demands None
Capabilities This task does not satisfy any demands for subsequent tasks in the job.
Command restrictions Any
Settable variables Any
Agent version All supported agent versions.
Task category Utility

:::moniker-end