Command Line task

Azure Pipelines | Azure DevOps Server 2019 | TFS 2018 | TFS 2017 | TFS 2015

Use this task in a build or release pipeline to run a program from the command prompt.


In Microsoft Team Foundation Server (TFS) 2018 and previous versions, build and release pipelines are called definitions, service connections are called service endpoints, stages are called environments, and jobs are called phases.



YAML snippet

# Command line
# Run a command line script using Bash on Linux and macOS and cmd.exe on Windows
- task: CmdLine@2
    #script: 'echo Write your commands here.' 
    #workingDirectory: # Optional
    #failOnStderr: false # Optional

The CmdLine task also has a shortcut syntax in YAML:

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


Argument Description
Script Contents of the script you want to run
Working directory Specify the working directory in which you want to run the command. If you leave it empty, the working directory is $(Build.SourcesDirectory).
Fail on standard error If this is true, this task will fail if any errors are written to stderr.
Environment variables A list of additional items to map into the process's environment. For example, secret variables are not automatically mapped. If you have a secret variable called Foo, you can map it in like this:

yaml - script: echo %MYSECRET% env: MySecret: $(Foo)
Control options


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

Open source

This task is open source on GitHub. Feedback and contributions are welcome.

Q & A

Where can I learn Windows commands?

An A-Z Index of the Windows CMD command line

Do I need an agent?

You need at least one agent to run your build or release. Get an agent for Linux, macOS, or Windows.

I can't select a default agent pool and I can't queue my build or release. How do I fix this?

See Agent pools.

I use TFS on-premises and I don't see some of these features. Why not?

Some of these features are available only on Azure Pipelines and not yet available on-premises. Some features are available on-premises if you have upgraded to the latest version of TFS.