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
を介して使用できるスクリプト実行に渡される引数を指定します。
Python インタープリターを pythonInterpreter
- する
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