共用方式為


CmdLine@2 - 命令行 v2 工作

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

語法

# 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

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


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

這很重要

您可能沒有意識到您正在執行批次處理檔。 例如,windows 上的 npm,以及您使用 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
需求 沒有
功能 此工作不符合作業中後續工作的任何需求。
命令限制 任意
Settable 變數 任意
代理程式版本 所有支援的代理程式版本。
工作類別 效用

另請參閱