Muokkaa

Jaa


CmdLine@2 - Command line v2 task

Use this task to run a command line script using Bash on Linux, macOS, and cmd.exe on Windows.

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.

Inputs

script - Script
string. Required. Default value: echo Write your commands here\n\necho Hello world.

The contents of the script you want to run.


script - Script
string. Required. Default value: echo Write your commands here\n\necho Use the environment variables input below to pass secret variables to this script.

The contents of the script you want to run.


workingDirectory - Working Directory
string.

Specifies the working directory to run commands. If you leave it empty, the working directory is $(Build.SourcesDirectory).


failOnStderr - Fail on Standard Error
boolean. Default value: false.

If the value is set to true, the task fails if any errors are written to the Standard Error stream.


Task control options

All tasks have control options in addition to their task inputs. For more information, see Control options and common task properties.

Output variables

None.

Remarks

The command line has a shortcut in YAML: steps.script.

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

Running batch and .CMD files

Azure Pipelines puts your inline script contents into a temporary batch file (.cmd) in order to run it. When you want to run a batch file from another batch file in Windows CMD, you must use the call command, otherwise the first batch file is terminated. This will result in Azure Pipelines running your intended script up until the first batch file, then running the batch file, then ending the step. Additional lines in the first script aren't run. You should always prepend call before executing a batch file in an Azure Pipelines script step.

Important

You may not realize you're running a batch file. For example, npm on Windows, along with any tools that you install using npm install -g, are actually batch files. Always use call npm <command> to run NPM commands in a Command Line task on Windows.

Examples

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

Requirements

Requirement Description
Pipeline types YAML, Classic build, Classic release
Runs on Agent, DeploymentGroup
Demands None
Capabilities This task does not satisfy any demands for subsequent tasks in the job.
Command restrictions Any
Settable variables Any
Agent version All supported agent versions.
Task category Utility

See also