Bash@3 - Bash v3 작업
이 작업을 사용하여 macOS, Linux 또는 Windows에서 Bash 스크립트를 실행합니다.
메모
Windows 호스트에서 WSL 기본 배포에서 bash를 실행합니다. WSL을 설치해야 하며 에이전트가 실행되는 사용자에게는 배포 설정이 있어야 합니다. WSL은 Microsoft 호스팅 Windows 에이전트 이미지에 설치됩니다. 자세한 내용은 Microsoft 호스팅 에이전트 - 소프트웨어참조하세요.
통사론
# Bash v3
# Run a Bash script on macOS, Linux, or Windows.
- task: Bash@3
inputs:
#targetType: 'filePath' # 'filePath' | 'inline'. Type. Default: filePath.
filePath: # string. Required when targetType = filePath. Script Path.
#arguments: # string. Optional. Use when targetType = filePath. Arguments.
#script: # string. Required when targetType = inline. Script.
# Advanced
#workingDirectory: # string. Working Directory.
#failOnStderr: false # boolean. Fail on Standard Error. Default: false.
#bashEnvValue: # string. Set value for BASH_ENV environment variable.
# Bash v3
# Run a Bash script on macOS, Linux, or Windows.
- task: Bash@3
inputs:
#targetType: 'filePath' # 'filePath' | 'inline'. Type. Default: filePath.
filePath: # string. Required when targetType = filePath. Script Path.
#arguments: # string. Optional. Use when targetType = filePath. Arguments.
#script: # string. Required when targetType = inline. Script.
# Advanced
#workingDirectory: # string. Working Directory.
#failOnStderr: false # boolean. Fail on Standard Error. Default: false.
#noProfile: true # boolean. Don't load the profile startup/initialization files. Default: true.
#noRc: true # boolean. Don't read the `~/.bashrc' initialization file. Default: true.
# Bash v3
# Run a Bash script on macOS, Linux, or Windows.
- task: Bash@3
inputs:
#targetType: 'filePath' # 'filePath' | 'inline'. Type. Default: filePath.
filePath: # string. Required when targetType = filePath. Script Path.
#arguments: # string. Optional. Use when targetType = filePath. Arguments.
#script: # string. Required when targetType = inline. Script.
# Advanced
#workingDirectory: # string. Working Directory.
#failOnStderr: false # boolean. Fail on Standard Error. Default: false.
입력
targetType
-
형식
string
. 허용되는 값: filePath
(파일 경로), inline
. 기본값: filePath
.
대상 스크립트 유형: 파일 경로 또는 인라인입니다.
filePath
-
스크립트 경로
string
.
targetType = filePath
때 필요합니다.
실행할 스크립트의 경로입니다. 정규화된 경로이거나 $(System.DefaultWorkingDirectory)
상대 경로여야 합니다.
arguments
-
인수
string
. 선택적.
targetType = filePath
때 사용합니다.
셸 스크립트에 전달된 인수입니다. 서수 매개 변수 또는 명명된 매개 변수입니다.
script
-
스크립트
string
.
targetType = inline
때 필요합니다. 기본값: # Write your commands here\n\necho 'Hello world'
.
스크립트의 내용입니다.
script
-
스크립트
string
.
targetType = inline
때 필요합니다. 기본값: # Write your commands here\n\n# Use the environment variables input below to pass secret variables to this script
.
스크립트의 내용입니다.
workingDirectory
-
작업 디렉터리
string
.
명령을 실행할 작업 디렉터리를 지정합니다. 비워 두면 작업 디렉터리가 $(Build.SourcesDirectory) .
표준 오류failOnStderr
- 실패
boolean
. 기본값: false
.
이 경우 오류가 StandardError
스트림에 기록되면 이 작업이 실패합니다.
bashEnvValue
-
BASH_ENV 환경 변수 값 설정
string
.
입력을 지정하면 해당 값이 확장되고 스크립트를 실행하기 전에 실행할 시작 파일의 경로로 사용됩니다. 환경 변수 BASH_ENV
이미 정의된 경우 태스크는 현재 작업에 대해서만 이 변수를 재정의합니다. Bash 시작 파일 대해 자세히 알아봅니다.
noProfile
-
프로필 시작/초기화 파일 로드하지 마세요.
boolean
. 기본값: true
.
시스템 전체 시작 파일 /etc/profile
또는 개인 초기화 파일을 로드하지 마세요.
noRc
- **~/.bashrc' initialization file**<br>
부울. Default value:
true'를 읽지 마세요.
작업 제어 옵션
모든 작업에는 작업 입력 외에도 제어 옵션이 있습니다. 자세한 내용은 컨트롤 옵션 및 일반적인 작업 속성참조하세요.
출력 변수
없음.
발언
bash 작업에는 yaML에서 steps.bash 바로 가기가 있습니다.
steps:
- bash: string # Required as first property. An inline script.
## Other task inputs
Bash 작업은 시스템에서 첫 번째 Bash 구현을 찾습니다.
Linux/macOS 또는 Windows의 where bash
which bash
실행하면 어떤 항목을 선택할지 알 수 있습니다.
Bash 시작 파일에 대한 정보
Bash 작업은 Bash를 비대화형 비 로그인 셸로 호출합니다. Bash가 비대화형으로 시작되면 셸 스크립트를 실행하기 위해 Bash는 환경에서 BASH_ENV
변수를 찾고, 해당 값이 나타나면 해당 값을 펼치고, 값을 파일 이름으로 사용하여 읽고 실행합니다.
파이프라인에서 BASH_ENV
환경 변수를 정의하는 몇 가지 옵션이 있습니다. 첫째, BASH_ENV
환경 변수를 파이프라인 변수로 설정할 수 있습니다. 이 경우 Bash 태스크의 각 인스턴스는 BASH_ENV
변수의 값을 전개하고 해당 값을 사용합니다.
variables:
BASH_ENV: "~/.profile"
steps:
- task: Bash@3
inputs:
targetType: 'inline'
script: env
또 다른 옵션은 Bash 태스크의 특정 인스턴스에 대한 BASH_ENV
설정하는 것입니다. 이 작업을 수행하는 방법에는 두 가지가 있습니다.
첫 번째 방법은 bashEnvValue
작업 입력을 사용하는 것입니다. 참조 예제를 참조하세요.
steps:
- task: Bash@3
inputs:
targetType: 'inline'
script: env
bashEnvValue: '~/.profile'
또 다른 방법은 BASH_ENV
변수를 env
키워드를 통해 파이프라인 작업의 환경 변수로 설정하는 것입니다. 예를 들면 다음과 같습니다.
- task: Bash@3
inputs:
targetType: 'inline'
script: env
env:
BASH_ENV: '~/.profile'
메모
bashEnvValue
입력이 Bash 태스크에 정의된 경우 파이프라인 작업은 환경에서 BASH_ENV
환경 변수가 이미 정의된 경우 bashEnvValue
입력의 값으로 BASH_ENV
변수의 값을 재정의합니다.
리포지토리에 체크 인된 Bash 스크립트는 실행 파일(chmod +x
)을 설정해야 합니다.
그렇지 않으면 태스크에서 경고를 표시하고 대신 파일을 source
.
예제
모든 태스크에서공통적인 env
매개 변수를 사용하여 변수에 매핑할 수 있으며 프로세스 환경에 매핑할 추가 항목의 목록입니다.
예를 들어 비밀 변수는 자동으로 매핑되지 않습니다.
Foo
라는 비밀 변수가 있는 경우 다음과 같이 매핑할 수 있습니다.
steps:
- task: Bash@3
inputs:
targetType: 'inline'
script: echo $MYSECRET
env:
MYSECRET: $(Foo)
macOS 또는 Linux에서 위의 예제는 다음과 같습니다.
steps:
- script: echo $MYSECRET
env:
MYSECRET: $(Foo)