이 작업을 사용하여 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 버전 작업을 실행하여 PATH에 Python 버전을 추가합니다.
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