CmdLine@2 - 命令行 v2 工作

使用此工作在 Windows 上使用 Bash 在 Linux、macOS 和 cmd.exe 上執行命令行腳本。

Syntax

# Command Line v2
# Run a command line script using Bash on Linux and macOS and cmd.exe on Windows.
- task: CmdLine@2
  inputs:
    script: # string. Required. Script. 
  # Advanced
    #workingDirectory: # string. Working Directory. 
    #failOnStderr: false # boolean. Fail on Standard Error. Default: false.

輸入

script - 腳本
string. 必要。 預設值:echo Write your commands here\n\necho Hello world

您想要執行的指令碼內容。


script - 腳本
string. 必要。 預設值:echo Write your commands here\n\necho Use the environment variables input below to pass secret variables to this script

您想要執行的指令碼內容。


workingDirectory - 工作目錄
string.

指定要執行命令的工作目錄。 如果您將它保留空白,則工作目錄為 $ (Build.SourcesDirectory)


failOnStderr - 標準錯誤失敗
boolean. 預設值:false

如果值設定為 true,則如果有任何錯誤寫入標準錯誤資料流程,工作就會失敗。


工作控制選項

除了工作輸入之外,所有工作都有控制選項。 如需詳細資訊,請參閱 控制選項和一般工作屬性

輸出變數

無。

備註

命令行在 YAML 中具有快捷方式: steps.script

- script: # inline script
  workingDirectory: #
  displayName: #
  failOnStderr: #
  env: { string: string } # mapping of environment variables to add

執行批次與 。CMD 檔案

Azure Pipelines 會將內嵌指令碼內容放入暫存批次檔 (.cmd),以執行。 當您想要從 Windows CMD 中的另一個批次處理檔執行批處理檔時,您必須使用 call 命令,否則會終止第一個批處理檔。 這會導致 Azure Pipelines 執行預定的指令碼,直到第一個批次檔,然後執行批次檔,然後結束步驟。 不會執行第一個指令碼中的其他行。 您應該一律在 Azure Pipelines 指令本步驟中執行批次處理檔之前加上 call

重要

您可能不知道您正在執行批次處理檔。 例如, npm 在 Windows 上,以及您使用 安裝 npm install -g的任何工具,實際上是批處理檔。 一律使用 call npm <command> 在 Windows 上的命令行工作中執行 NPM 命令。

範例

steps:
- script: date /t
  displayName: Get the date
- script: dir
  workingDirectory: $(Agent.BuildDirectory)
  displayName: List contents of a folder
- script: |
    set MYVAR=foo
    set
  displayName: Set a variable and then display all
  env:
    aVarFromYaml: someValue

規格需求

需求 描述
管線類型 YAML、傳統組建、傳統版本
在上執行 Agent、DeploymentGroup
要求
Capabilities 此工作不符合作業中後續工作的任何需求。
命令限制 任何
可設定變數 任何
代理程式版本 所有支援的代理程式版本。
工作類別 公用程式

另請參閱