PythonScript@0 - Python 脚本 v0 任务
使用此任务可以运行 Python 文件或内联脚本。
语法
# 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.
输入
scriptSource
-
脚本源
string
。 必填。 允许的值:filePath
(文件路径),inline
。 默认值:filePath
。
指定脚本是源树中的文件,还是在此任务中内联写入。
scriptPath
-
脚本路径
string
。
scriptSource = filePath
时是必需的。
指定要执行的脚本的路径。 必须是完全限定的路径或相对于 $(System.DefaultWorkingDirectory)
。
script
-
脚本
string
。
scriptSource = inline
时是必需的。
指定要运行的 Python 脚本。
arguments
-
参数
string
。
指定传递给可通过 sys.argv
执行的脚本执行的参数,就像在命令行上传递这些参数一样。
pythonInterpreter
-
Python 解释器
string
。
指定要使用的 Python 解释器的绝对路径。 如果未指定,任务将使用 PATH 中的解释器。
运行 使用 Python 版本 任务将 Python 版本添加到 PATH。
workingDirectory
-
工作目录
string
。
指定运行脚本的工作目录。 如果未指定,将使用 System.DefaultWorkingDirectory
的值。 对于生成,此变量默认为存储库的根目录。 对于版本,默认为项目目录的根目录。
failOnStderr
-
标准错误 失败
boolean
。 默认值:false
。
如果设置为 true
,则向 stderr
流写入任何文本时,此任务将失败。
任务控制选项
除任务输入之外,所有任务都具有控制选项。 有关详细信息,请参阅 控件选项和常见任务属性。
输出变量
没有。
注解
默认情况下,此任务将从系统路径调用 python
。
运行 使用 Python 版本 将所需的版本置于系统路径中。
例子
运行内联 Python 脚本。
- task: PythonScript@0
inputs:
scriptSource: 'inline'
script: |
print('Hello world 1')
print('Hello world 2')
运行使用环境变量的内联 Python 脚本。
- task: PythonScript@0
inputs:
scriptSource: 'inline'
script: |
import os
print(f'Environment variable MY_VAR: {os.getenv("MY_VAR")}')
env:
MY_VAR: 'Hello, World!'
从工作目录运行 Python 脚本。 如果将任何文本写入 stderr
流,任务将失败。
- task: PythonScript@0
inputs:
scriptSource: 'filePath'
scriptPath: 'scripts/hello_world.py'
workingDirectory: '$(Build.SourcesDirectory)/scripts'
failOnStderr: true