Bash@3 - Bash v3 작업

이 작업을 사용하여 macOS, Linux 또는 Windows에서 Bash 스크립트를 실행합니다.

Syntax

# 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- **부울. Default value: true를 ~/.bashrc' initialization file**<br> 읽지 마세요.'


작업 제어 옵션

모든 작업에는 작업 입력 외에 제어 옵션이 있습니다. 자세한 내용은 컨트롤 옵션 및 일반적인 작업 속성을 참조하세요.

출력 변수

없음

설명

bash 작업에는 YAML: steps.bash의 바로 가기가 있습니다.

steps:
- bash: string # Required as first property. An inline script. 
  ## Other task inputs

Bash 작업은 시스템에서 첫 번째 Bash 구현을 찾습니다. Linux/macOS 또는 where bash Windows에서 실행 which bash 하면 어떤 항목을 선택할지 알 수 있습니다.

Bash 시작 파일에 대한 정보

Bash 작업은 Bash를 비대화형 비 로그인 셸로 호출합니다. Bash가 비대화형으로 시작되면 셸 스크립트를 실행하기 위해 Bash는 환경에서 변수 BASH_ENV 를 찾고, 변수가 나타나면 해당 값을 펼치고, 값을 파일 이름으로 사용하여 읽고 실행합니다.

파이프라인에서 환경 변수를 BASH_ENV 정의하는 몇 가지 옵션이 있습니다. 먼저 환경 변수를 파이프라인 변수로 설정할 BASH_ENV 수 있습니다. 이 경우 Bash 작업의 각 instance 변수의 BASH_ENV 값을 전개하고 해당 값을 사용합니다.

variables:
  BASH_ENV: "~/.profile"

steps:
- task: Bash@3
  inputs:
    targetType: 'inline'
    script: env

또 다른 옵션은 Bash 작업의 특정 instance 대해 설정하는 BASH_ENV 것입니다. 이 작업을 수행하는 방법에는 두 가지가 있습니다.

첫 번째 방법은 작업 입력을 bashEnvValue 사용하는 것입니다. 참조 예제를 참조하세요.

steps:
- task: Bash@3
  inputs:
    targetType: 'inline'
    script: env
    bashEnvValue: '~/.profile'

또 다른 방법은 변수를 BASH_ENV 키워드(keyword) 통해 env 파이프라인 작업의 환경 변수로 설정하는 것입니다. 예를 들면 다음과 같습니다.

- task: Bash@3
  inputs:
    targetType: 'inline'
    script: env
  env:
    BASH_ENV: '~/.profile'

참고

입력이 bashEnvValue Bash 태스크에 정의된 경우 파이프라인 태스크는 환경 변수가 환경에 이미 정의된 경우 입력의 값으로 변수 값을 bashEnvValue 재정의 BASH_ENVBASH_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)

요구 사항

요구 사항 Description
파이프라인 유형 YAML, 클래식 빌드, 클래식 릴리스
실행 중 에이전트, DeploymentGroup
요청 없음
Capabilities 이 작업은 작업의 후속 작업에 대한 요구를 충족하지 않습니다.
명령 제한 사항 모두
Settable 변수 모두
에이전트 버전 2.115.0 이상
작업 범주 유틸리티