Batch Script task
Azure Pipelines | Azure DevOps Server 2020 | Azure DevOps Server 2019 | TFS 2018 - TFS 2015
Use this task to run a Windows .bat or .cmd script. Optionally, allow it to permanently modify environment variables.
This task is not compatible with Windows containers. If you need to run a batch script on a Windows container, use the command line task instead.
For information on supporting multiple platforms, see cross platform scripting.
In Microsoft Team Foundation Server (TFS) 2018 and previous versions, build and release pipelines are called definitions, runs are called builds, 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
|(Required) Path of the cmd or bat script to execute. Should be fully qualified path or relative to the default working directory (please note that working directory could differ from 'workingFolder' which could be specified for this task).|
|(Optional) Specify arguments to pass to the script.|
|(Optional) Determines whether environment variable modifications will affect subsequent tasks
|(Optional) Current working directory when script is run. Defaults to the agent's default working directory|
Fail on Standard Error
|(Optional) If this is true, this task will fail if any 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.
Where can I learn Windows commands?
How do I set a variable so that it can be read by subsequent scripts and tasks?
To learn more about defining build variables in a script, see Define and modify your build variables in a script.
To learn more about defining release variables in a script, see Define and modify your release variables in a script.
Q: I'm having issues with publishing my artifacts. How can I view the detailed logs?
To enable detailed logs for your pipeline:
- Edit your pipeline and select Variables
- Add a new variable with the name
Q: Which variables are available to me?
$(Agent.BuildDirectory) are just few of the variables you can use in your pipeline. Variables are available as expressions or scripts.
Do I need an agent?
You need at least one agent to run your build or release.
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.
My NuGet push task is failing with the following error: "Error: unable to get local issuer certificate". How can I fix this?
This can be fixed by adding a trusted root certificate. You can either add the
NODE_EXTRA_CA_CERTS=file environment variable to your build agent, or you can add the
NODE.EXTRA.CA.CERTS=file task variable in your pipeline. See Node.js documentation for more details about this variable. See Set variables in a pipeline for instructions on setting a variable in your pipeline.