Task - Add Collection
Adds a collection of Tasks to the specified Job.
Note that each Task must have a unique ID. The Batch service may not return the results for each Task in the same order the Tasks were submitted in this request. If the server times out or the connection is closed during the request, the request may have been partially or fully processed, or not at all. In such cases, the user should re-issue the request. Note that it is up to the user to correctly handle failures when re-issuing a request. For example, you should use the same Task IDs during a retry so that if the prior operation succeeded, the retry will not create extra Tasks unexpectedly. If the response contains any Tasks which failed to add, a client can retry the request. In a retry, it is most efficient to resubmit only Tasks that failed to add, and to omit Tasks that were successfully added on the first attempt. The maximum lifetime of a Task from addition to completion is 180 days. If a Task has not completed within 180 days of being added it will be terminated by the Batch service and left in whatever state it was in at that time.
POST {batchUrl}/jobs/{jobId}/addtaskcollection?api-version=2024-07-01.20.0
POST {batchUrl}/jobs/{jobId}/addtaskcollection?timeout={timeout}&api-version=2024-07-01.20.0
URI Parameters
Name | In | Required | Type | Description |
---|---|---|---|---|
batch
|
path | True |
string |
The base URL for all Azure Batch service requests. |
job
|
path | True |
string |
The ID of the Job to which the Task collection is to be added. |
api-version
|
query | True |
string |
Client API Version. |
timeout
|
query |
integer int32 |
The maximum time that the server can spend processing the request, in seconds. The default is 2 minutes. If the value is larger than 120, the default will be used instead. |
Request Header
Media Types: "application/json; odata=minimalmetadata"
Name | Required | Type | Description |
---|---|---|---|
client-request-id |
string uuid |
The caller-generated request identity, in the form of a GUID with no decoration such as curly braces, e.g. 9C4D50EE-2D56-4CD3-8152-34347DC9F2B0. |
|
return-client-request-id |
boolean |
Whether the server should return the client-request-id in the response. |
|
ocp-date |
string date-time-rfc1123 |
The time the request was issued. Client libraries typically set this to the current system clock time; set it explicitly if you are calling the REST API directly. |
Request Body
Media Types: "application/json; odata=minimalmetadata"
Name | Required | Type | Description |
---|---|---|---|
value | True |
The collection of Tasks to add. The maximum count of Tasks is 100. |
Responses
Name | Type | Description |
---|---|---|
200 OK |
A response containing the results of the add Task collection operation. Headers
|
|
Other Status Codes |
Unexpected error |
Security
azure_auth
Microsoft Entra OAuth 2.0 auth code flow
Type:
oauth2
Flow:
implicit
Authorization URL:
https://login.microsoftonline.com/common/oauth2/authorize
Scopes
Name | Description |
---|---|
user_impersonation | Impersonate your user account |
Authorization
Type:
apiKey
In:
header
Examples
Add a basic collection of tasks |
Add a complex collection of tasks |
Add a basic collection of tasks
Sample request
POST account.region.batch.azure.com/jobs/jobId/addtaskcollection?api-version=2024-07-01.20.0
{
"value": [
{
"id": "simple1",
"commandLine": "cmd /c dir /s"
},
{
"id": "simple2",
"commandLine": "cmd /c dir /s"
}
]
}
Sample response
{
"value": [
{
"status": "success",
"taskId": "simple1",
"eTag": "0x8D3D623CD661246",
"lastModified": "2016-09-06T07:02:44.7589958Z",
"location": "https://account.region.batch.azure.com/jobs/jobId/tasks/simple1"
},
{
"status": "success",
"taskId": "simple2",
"eTag": "0x8D3D623CD7072CC",
"lastModified": "2016-09-06T07:02:44.8270028Z",
"location": "https://account.region.batch.azure.com/jobs/jobId/tasks/simple2"
}
]
}
Add a complex collection of tasks
Sample request
POST account.region.batch.azure.com/jobs/jobId/addtaskcollection?api-version=2024-07-01.20.0
{
"value": [
{
"id": "complex1",
"commandLine": "cmd /c dir /s",
"resourceFiles": [
{
"autoStorageContainerName": "containerName",
"filePath": "data"
}
],
"environmentSettings": [
{
"name": "env1",
"value": "value1"
},
{
"name": "env2",
"value": "value2"
}
],
"affinityInfo": {
"affinityId": "affinityId"
},
"constraints": {
"maxWallClockTime": "P1D",
"retentionTime": "P2D",
"maxTaskRetryCount": 5
},
"requiredSlots": 2,
"multiInstanceSettings": {
"numberOfInstances": 3,
"coordinationCommandLine": "cmd /c echo coordinating",
"commonResourceFiles": [
{
"httpUrl": "https://common.blob.core.windows.net/",
"filePath": "common.exe"
}
]
}
},
{
"id": "simple3",
"commandLine": "cmd /c dir /s"
}
]
}
Sample response
{
"value": [
{
"taskId": "simple3",
"status": "success",
"eTag": "0x8D3D623CE295629",
"lastModified": "2016-09-06T07:02:46.0386857Z",
"location": "https://account.region.batch.azure.com/jobs/jobId/tasks/simple3"
},
{
"taskId": "complex1",
"status": "success",
"eTag": "0x8D3D623CE29A412",
"lastModified": "2016-09-06T07:02:46.0406802Z",
"location": "https://account.region.batch.azure.com/jobs/jobId/tasks/complex1"
}
]
}
Definitions
Name | Description |
---|---|
Access |
The Batch resources to which the token grants access. |
Affinity |
A locality hint that can be used by the Batch service to select a Compute Node on which to start a Task. |
Application |
A reference to an Package to be deployed to Compute Nodes. |
Authentication |
The settings for an authentication token that the Task can use to perform Batch service operations. |
Auto |
The scope for the auto user |
Auto |
Specifies the parameters for the auto user that runs a Task on the Batch service. |
Batch |
An error response received from the Azure Batch service. |
Batch |
An item of additional information included in an Azure Batch error response. |
Compute |
The reference to a user assigned identity associated with the Batch pool which a compute node will use. |
Container |
The entry of path and mount mode you want to mount into task container. |
Container |
The paths which will be mounted to container task's container. |
Container |
A private container registry. |
Container |
The location of the container Task working directory. |
Dependency |
An action that the Batch service performs on Tasks that depend on this Task. |
Elevation |
The elevation level of the user. |
Environment |
An environment variable to be set on a Task process. |
Error |
An error message received in an Azure Batch error response. |
Exit |
How the Batch service should respond if a Task exits with a particular exit code. |
Exit |
A range of exit codes and how the Batch service should respond to exit codes within that range. |
Exit |
Specifies how the Batch service should respond when the Task completes. |
Exit |
Specifies how the Batch service responds to a particular exit condition. |
Http |
An HTTP header name-value pair |
Job |
An action to take on the Job containing the Task, if the Task completes with the given exit condition and the Job's onTaskFailed property is 'performExitOptionsJobAction'. |
Multi |
Settings which specify how to run a multi-instance Task. |
Output |
A specification for uploading files from an Azure Batch Compute Node to another location after the Batch service has finished executing the Task process. |
Output |
Specifies a file upload destination within an Azure blob storage container. |
Output |
The destination to which a file should be uploaded. |
Output |
The conditions under which a Task output file or set of files should be uploaded. |
Output |
Details about an output file upload operation, including under what conditions to perform the upload. |
Resource |
A single file or multiple files to be downloaded to a Compute Node. |
Task |
A collection of Azure Batch Tasks to add. |
Task |
The result of adding a collection of Tasks to a Job. |
Task |
An Azure Batch Task to add. |
Task |
Result for a single Task added as part of an add Task collection operation. |
Task |
The status of the add Task request. |
Task |
Execution constraints to apply to a Task. |
Task |
The container settings for a Task. |
Task |
Specifies any dependencies of a Task. Any Task that is explicitly specified or within a dependency range must complete before the dependant Task will be scheduled. |
Task |
A range of Task IDs that a Task can depend on. All Tasks with IDs in the range must complete successfully before the dependent Task can be scheduled. |
User |
The definition of the user identity under which the Task is run. |
AccessScope
The Batch resources to which the token grants access.
Name | Type | Description |
---|---|---|
job |
string |
Grants access to perform all operations on the Job containing the Task. |
AffinityInformation
A locality hint that can be used by the Batch service to select a Compute Node on which to start a Task.
Name | Type | Description |
---|---|---|
affinityId |
string |
An opaque string representing the location of a Compute Node or a Task that has run previously. |
ApplicationPackageReference
A reference to an Package to be deployed to Compute Nodes.
Name | Type | Description |
---|---|---|
applicationId |
string |
The ID of the application to deploy. |
version |
string |
The version of the application to deploy. If omitted, the default version is deployed. |
AuthenticationTokenSettings
The settings for an authentication token that the Task can use to perform Batch service operations.
Name | Type | Description |
---|---|---|
access |
The Batch resources to which the token grants access. |
AutoUserScope
The scope for the auto user
Name | Type | Description |
---|---|---|
pool |
string |
Specifies that the Task runs as the common auto user Account which is created on every Compute Node in a Pool. |
task |
string |
Specifies that the service should create a new user for the Task. |
AutoUserSpecification
Specifies the parameters for the auto user that runs a Task on the Batch service.
Name | Type | Description |
---|---|---|
elevationLevel |
The elevation level of the auto user. |
|
scope |
The scope for the auto user |
BatchError
An error response received from the Azure Batch service.
Name | Type | Description |
---|---|---|
code |
string |
An identifier for the error. Codes are invariant and are intended to be consumed programmatically. |
message |
A message describing the error, intended to be suitable for display in a user interface. |
|
values |
A collection of key-value pairs containing additional details about the error. |
BatchErrorDetail
An item of additional information included in an Azure Batch error response.
Name | Type | Description |
---|---|---|
key |
string |
An identifier specifying the meaning of the Value property. |
value |
string |
The additional information included with the error response. |
ComputeNodeIdentityReference
The reference to a user assigned identity associated with the Batch pool which a compute node will use.
Name | Type | Description |
---|---|---|
resourceId |
string |
The ARM resource id of the user assigned identity. |
ContainerHostBatchBindMountEntry
The entry of path and mount mode you want to mount into task container.
Name | Type | Description |
---|---|---|
isReadOnly |
boolean |
Mount this source path as read-only mode or not. Default value is false (read/write mode). |
source |
The path which be mounted to container customer can select. |
ContainerHostDataPath
The paths which will be mounted to container task's container.
Name | Type | Description |
---|---|---|
Applications |
string |
The applications path. |
JobPrep |
string |
The job-prep task path. |
Shared |
string |
The path for multi-instances task to shared their files. |
Startup |
string |
The path for start task. |
Task |
string |
The task path. |
VfsMounts |
string |
The path contains all virtual file systems are mounted on this node. |
ContainerRegistry
A private container registry.
Name | Type | Description |
---|---|---|
identityReference |
The reference to the user assigned identity to use to access an Azure Container Registry instead of username and password. |
|
password |
string |
The password to log into the registry server. |
registryServer |
string |
The registry URL. |
username |
string |
The user name to log into the registry server. |
ContainerWorkingDirectory
The location of the container Task working directory.
Name | Type | Description |
---|---|---|
containerImageDefault |
string |
Use the working directory defined in the container Image. Beware that this directory will not contain the Resource Files downloaded by Batch. |
taskWorkingDirectory |
string |
Use the standard Batch service Task working directory, which will contain the Task Resource Files populated by Batch. |
DependencyAction
An action that the Batch service performs on Tasks that depend on this Task.
Name | Type | Description |
---|---|---|
block |
string |
Blocks tasks waiting on this task, preventing them from being scheduled. |
satisfy |
string |
Satisfy tasks waiting on this task; once all dependencies are satisfied, the task will be scheduled to run. |
ElevationLevel
The elevation level of the user.
Name | Type | Description |
---|---|---|
admin |
string |
The user is a user with elevated access and operates with full Administrator permissions. |
nonadmin |
string |
The user is a standard user without elevated access. |
EnvironmentSetting
An environment variable to be set on a Task process.
Name | Type | Description |
---|---|---|
name |
string |
The name of the environment variable. |
value |
string |
The value of the environment variable. |
ErrorMessage
An error message received in an Azure Batch error response.
Name | Type | Description |
---|---|---|
lang |
string |
The language code of the error message |
value |
string |
The text of the message. |
ExitCodeMapping
How the Batch service should respond if a Task exits with a particular exit code.
Name | Type | Description |
---|---|---|
code |
integer |
A process exit code. |
exitOptions |
How the Batch service should respond if the Task exits with this exit code. |
ExitCodeRangeMapping
A range of exit codes and how the Batch service should respond to exit codes within that range.
Name | Type | Description |
---|---|---|
end |
integer |
The last exit code in the range. |
exitOptions |
How the Batch service should respond if the Task exits with an exit code in the range start to end (inclusive). |
|
start |
integer |
The first exit code in the range. |
ExitConditions
Specifies how the Batch service should respond when the Task completes.
Name | Type | Description |
---|---|---|
default |
How the Batch service should respond if the Task fails with an exit condition not covered by any of the other properties. |
|
exitCodeRanges |
A list of Task exit code ranges and how the Batch service should respond to them. |
|
exitCodes |
A list of individual Task exit codes and how the Batch service should respond to them. |
|
fileUploadError |
How the Batch service should respond if a file upload error occurs. |
|
preProcessingError |
How the Batch service should respond if the Task fails to start due to an error. |
ExitOptions
Specifies how the Batch service responds to a particular exit condition.
Name | Type | Description |
---|---|---|
dependencyAction |
An action that the Batch service performs on Tasks that depend on this Task. |
|
jobAction |
An action to take on the Job containing the Task, if the Task completes with the given exit condition and the Job's onTaskFailed property is 'performExitOptionsJobAction'. |
HttpHeader
An HTTP header name-value pair
Name | Type | Description |
---|---|---|
name |
string |
The case-insensitive name of the header to be used while uploading output files |
value |
string |
The value of the header to be used while uploading output files |
JobAction
An action to take on the Job containing the Task, if the Task completes with the given exit condition and the Job's onTaskFailed property is 'performExitOptionsJobAction'.
Name | Type | Description |
---|---|---|
disable |
string |
Disable the Job. This is equivalent to calling the disable Job API, with a disableTasks value of requeue. |
none |
string |
Take no action. |
terminate |
string |
Terminate the Job. The terminateReason in the Job's executionInfo is set to "TaskFailed". |
MultiInstanceSettings
Settings which specify how to run a multi-instance Task.
Name | Type | Description |
---|---|---|
commonResourceFiles |
A list of files that the Batch service will download before running the coordination command line. |
|
coordinationCommandLine |
string |
The command line to run on all the Compute Nodes to enable them to coordinate when the primary runs the main Task command. |
numberOfInstances |
integer |
The number of Compute Nodes required by the Task. |
OutputFile
A specification for uploading files from an Azure Batch Compute Node to another location after the Batch service has finished executing the Task process.
Name | Type | Description |
---|---|---|
destination |
The destination for the output file(s). |
|
filePattern |
string |
A pattern indicating which file(s) to upload. |
uploadOptions |
Additional options for the upload operation, including under what conditions to perform the upload. |
OutputFileBlobContainerDestination
Specifies a file upload destination within an Azure blob storage container.
Name | Type | Description |
---|---|---|
containerUrl |
string |
The URL of the container within Azure Blob Storage to which to upload the file(s). |
identityReference |
The reference to the user assigned identity to use to access Azure Blob Storage specified by containerUrl |
|
path |
string |
The destination blob or virtual directory within the Azure Storage container. |
uploadHeaders |
A list of name-value pairs for headers to be used in uploading output files |
OutputFileDestination
The destination to which a file should be uploaded.
Name | Type | Description |
---|---|---|
container |
A location in Azure blob storage to which files are uploaded. |
OutputFileUploadCondition
The conditions under which a Task output file or set of files should be uploaded.
Name | Type | Description |
---|---|---|
taskcompletion |
string |
Upload the file(s) after the Task process exits, no matter what the exit code was. |
taskfailure |
string |
Upload the file(s) only after the Task process exits with a nonzero exit code. |
tasksuccess |
string |
Upload the file(s) only after the Task process exits with an exit code of 0. |
OutputFileUploadOptions
Details about an output file upload operation, including under what conditions to perform the upload.
Name | Type | Description |
---|---|---|
uploadCondition |
The conditions under which the Task output file or set of files should be uploaded. |
ResourceFile
A single file or multiple files to be downloaded to a Compute Node.
Name | Type | Description |
---|---|---|
autoStorageContainerName |
string |
The storage container name in the auto storage Account. |
blobPrefix |
string |
The blob prefix to use when downloading blobs from an Azure Storage container. Only the blobs whose names begin with the specified prefix will be downloaded. |
fileMode |
string |
The file permission mode attribute in octal format. |
filePath |
string |
The location on the Compute Node to which to download the file(s), relative to the Task's working directory. |
httpUrl |
string |
The URL of the file to download. |
identityReference |
The reference to the user assigned identity to use to access Azure Blob Storage specified by storageContainerUrl or httpUrl |
|
storageContainerUrl |
string |
The URL of the blob container within Azure Blob Storage. |
TaskAddCollectionParameter
A collection of Azure Batch Tasks to add.
Name | Type | Description |
---|---|---|
value |
The collection of Tasks to add. The maximum count of Tasks is 100. |
TaskAddCollectionResult
The result of adding a collection of Tasks to a Job.
Name | Type | Description |
---|---|---|
value |
The results of the add Task collection operation. |
TaskAddParameter
An Azure Batch Task to add.
Name | Type | Description |
---|---|---|
affinityInfo |
A locality hint that can be used by the Batch service to select a Compute Node on which to start the new Task. |
|
applicationPackageReferences |
A list of Packages that the Batch service will deploy to the Compute Node before running the command line. |
|
authenticationTokenSettings |
The settings for an authentication token that the Task can use to perform Batch service operations. |
|
commandLine |
string |
The command line of the Task. |
constraints |
The execution constraints that apply to this Task. |
|
containerSettings |
The settings for the container under which the Task runs. |
|
dependsOn |
The Tasks that this Task depends on. |
|
displayName |
string |
A display name for the Task. |
environmentSettings |
A list of environment variable settings for the Task. |
|
exitConditions |
Specifies how the Batch service should respond when the Task completes. |
|
id |
string |
A string that uniquely identifies the Task within the Job. |
multiInstanceSettings |
An object that indicates that the Task is a multi-instance Task, and contains information about how to run the multi-instance Task. |
|
outputFiles |
A list of files that the Batch service will upload from the Compute Node after running the command line. |
|
requiredSlots |
integer |
The number of scheduling slots that the Task required to run. |
resourceFiles |
A list of files that the Batch service will download to the Compute Node before running the command line. |
|
userIdentity |
The user identity under which the Task runs. |
TaskAddResult
Result for a single Task added as part of an add Task collection operation.
Name | Type | Description |
---|---|---|
eTag |
string |
The ETag of the Task, if the Task was successfully added. |
error |
The error encountered while attempting to add the Task. |
|
lastModified |
string |
The last modified time of the Task. |
location |
string |
The URL of the Task, if the Task was successfully added. |
status |
The status of the add Task request. |
|
taskId |
string |
The ID of the Task for which this is the result. |
TaskAddStatus
The status of the add Task request.
Name | Type | Description |
---|---|---|
clienterror |
string |
The Task failed to add due to a client error and should not be retried without modifying the request as appropriate. |
servererror |
string |
Task failed to add due to a server error and can be retried without modification. |
success |
string |
The Task was added successfully. |
TaskConstraints
Execution constraints to apply to a Task.
Name | Type | Description |
---|---|---|
maxTaskRetryCount |
integer |
The maximum number of times the Task may be retried. The Batch service retries a Task if its exit code is nonzero. |
maxWallClockTime |
string |
The maximum elapsed time that the Task may run, measured from the time the Task starts. If the Task does not complete within the time limit, the Batch service terminates it. |
retentionTime |
string |
The minimum time to retain the Task directory on the Compute Node where it ran, from the time it completes execution. After this time, the Batch service may delete the Task directory and all its contents. |
TaskContainerSettings
The container settings for a Task.
Name | Type | Description |
---|---|---|
containerHostBatchBindMounts |
The paths you want to mounted to container task. |
|
containerRunOptions |
string |
Additional options to the container create command. |
imageName |
string |
The Image to use to create the container in which the Task will run. |
registry |
The private registry which contains the container Image. |
|
workingDirectory |
The location of the container Task working directory. |
TaskDependencies
Specifies any dependencies of a Task. Any Task that is explicitly specified or within a dependency range must complete before the dependant Task will be scheduled.
Name | Type | Description |
---|---|---|
taskIdRanges |
The list of Task ID ranges that this Task depends on. All Tasks in all ranges must complete successfully before the dependent Task can be scheduled. |
|
taskIds |
string[] |
The list of Task IDs that this Task depends on. All Tasks in this list must complete successfully before the dependent Task can be scheduled. |
TaskIdRange
A range of Task IDs that a Task can depend on. All Tasks with IDs in the range must complete successfully before the dependent Task can be scheduled.
Name | Type | Description |
---|---|---|
end |
integer |
The last Task ID in the range. |
start |
integer |
The first Task ID in the range. |
UserIdentity
The definition of the user identity under which the Task is run.
Name | Type | Description |
---|---|---|
autoUser |
The auto user under which the Task is run. |
|
username |
string |
The name of the user identity under which the Task is run. |