Muokkaa

Jaa


BatchScript@1 - Batch script v1 task

Use this task to run a Windows .bat or .cmd script. Optionally, the .bat or .cmd script can permanently modify environment variables.

Syntax

# Batch script v1
# Run a Windows command or batch script and optionally allow it to change the environment.
- task: BatchScript@1
  inputs:
    filename: # string. Required. Path. 
    #arguments: # string. Arguments. 
    #modifyEnvironment: False # boolean. Modify Environment. Default: False.
  # Advanced
    #workingFolder: # string. Working folder. 
    #failOnStandardError: false # boolean. Fail on Standard Error. Default: false.
# Batch Script v1
# Run a windows cmd or bat script and optionally allow it to change the environment.
- task: BatchScript@1
  inputs:
    filename: # string. Required. Path. 
    #arguments: # string. Arguments. 
    #modifyEnvironment: False # boolean. Modify Environment. Default: False.
  # Advanced
    #workingFolder: # string. Working folder. 
    #failOnStandardError: false # boolean. Fail on Standard Error. Default: false.

Inputs

filename - Path
string. Required.

The path of the .cmd or .bat script to execute. This should be a fully qualified path or one relative to the default working directory. (Please note that the working directory could differ from workingFolder, which could be specified for this task.)


arguments - Arguments
string.

The arguments passed to the .cmd or .bat script.


modifyEnvironment - Modify Environment
boolean. Default value: False.

Determines whether environment variable modifications will affect subsequent tasks.


workingFolder - Working folder
string.

The current working directory when a script is run. This defaults to the folder where the script is located.


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

If this is true, this task will fail if any errors are written to the StandardError 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

Use this task to run a Windows .bat or .cmd script. Optionally, allow it to permanently modify environment variables.

Note

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.

Examples

Create 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.

To run this script, add the following task to your pipeline.

- task: BatchScript@1
  inputs:
    filename: 'test.bat'

Requirements

Requirement Description
Pipeline types YAML, Classic build, Classic release
Runs on Agent, DeploymentGroup
Demands Self-hosted agents must have capabilities that match the following demands to run jobs that use this task: Cmd
Capabilities This task does not satisfy any demands for subsequent tasks in the job.
Command restrictions Any
Settable variables Any
Agent version 1.83.0 or greater
Task category Utility