Redaguoti

Bendrinti naudojant


PythonScript@0 - Python script v0 task

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

Syntax

# 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.
# 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.

Inputs

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.


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).


script - Script
string. Required when scriptSource = inline.

Specifies the Python script to run.


arguments - Arguments
string.

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


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.


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.


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.


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

None.

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

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