Batch Script 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 Windows .bat or .cmd script and optionally allow it to change the stage.
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.
# Batch script # Run a Windows command or batch script and optionally allow it to change the environment - task: BatchScript@1 inputs: filename: #arguments: # Optional #modifyEnvironment: False # Optional #workingFolder: # Optional #failOnStandardError: false # Optional
Specify the path to the .bat or .cmd script you want to run. The path must be a fully qualified path or a valid path relative to the default working directory.
In Team Foundation Build, this directory is $(Build.SourcesDirectory).
|Arguments||Specify arguments to pass to the script.|
|Modify environment||Select this check box if you want stage variable modifications in the script to affect subsequent tasks.||Advanced|
|Working folder||Specify the working directory in which you want to run the script. If you leave it empty, the working directory is the folder where the script is located.|
|Fail on standard error||Select this check box if you want the build to fail if errors are written to the StandardError stream.|
test.bat at the root of your repo:
@echo off echo Hello World from %AGENT_NAME%. echo My ID is %AGENT_ID%. echo AGENT_WORKFOLDER contents: @dir %AGENT_WORKFOLDER% echo AGENT_BUILDDIRECTORY contents: @dir %AGENT_BUILDDIRECTORY% echo BUILD_SOURCESDIRECTORY contents: @dir %BUILD_SOURCESDIRECTORY% echo Over and out.
On the Build tab of a build pipeline, add this task:
This task is open source on GitHub. Feedback and contributions are welcome.
Q & A
Where can I learn Windows commands?
How do I set a variable so that it can be read by subsequent scripts and tasks?
Q: I'm having problems. How can I troubleshoot them?
A: Try this:
On the variables tab, add
system.debugand set it to
true. Select to allow at queue time.
In the explorer tab, view your completed build and click the build step to view its output.
The control options arguments described above can also be useful when you're trying to isolate a problem.
Q: How do variables work? What variables are available for me to use in the arguments?
$(Agent.BuildDirectory) are just a few of the variables you can use.
Variables are available in expressions as well as scripts; see variables to learn more about how to use them.
There are some predefined build and release variables you can also rely on.
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'm having problems. How can I troubleshoot them?
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.