你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn。
BatchClient.CreateJob Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Overloads
CreateJob(BatchJobCreateContent, Nullable<Int32>, Nullable<DateTimeOffset>, CancellationToken) |
Creates a Job to the specified Account. |
CreateJob(RequestContent, Nullable<Int32>, Nullable<DateTimeOffset>, RequestContext) |
[Protocol Method] Creates a Job to the specified Account.
|
CreateJob(BatchJobCreateContent, Nullable<Int32>, Nullable<DateTimeOffset>, CancellationToken)
- Source:
- BatchClient.cs
Creates a Job to the specified Account.
public virtual Azure.Response CreateJob (Azure.Compute.Batch.BatchJobCreateContent job, int? timeOutInSeconds = default, DateTimeOffset? ocpdate = default, System.Threading.CancellationToken cancellationToken = default);
abstract member CreateJob : Azure.Compute.Batch.BatchJobCreateContent * Nullable<int> * Nullable<DateTimeOffset> * System.Threading.CancellationToken -> Azure.Response
override this.CreateJob : Azure.Compute.Batch.BatchJobCreateContent * Nullable<int> * Nullable<DateTimeOffset> * System.Threading.CancellationToken -> Azure.Response
Public Overridable Function CreateJob (job As BatchJobCreateContent, Optional timeOutInSeconds As Nullable(Of Integer) = Nothing, Optional ocpdate As Nullable(Of DateTimeOffset) = Nothing, Optional cancellationToken As CancellationToken = Nothing) As Response
Parameters
The Job to be created.
The maximum time that the server can spend processing the request, in seconds. The default is 30 seconds. If the value is larger than 30, the default will be used instead.".
- ocpdate
- Nullable<DateTimeOffset>
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.
- cancellationToken
- CancellationToken
The cancellation token to use.
Returns
Exceptions
job
is null.
Examples
This sample shows how to call CreateJob.
Uri endpoint = new Uri("<https://my-service.azure.com>");
TokenCredential credential = new DefaultAzureCredential();
BatchClient client = new BatchClient(endpoint, credential);
BatchJobCreateContent job = new BatchJobCreateContent("<id>", new BatchPoolInfo());
Response response = client.CreateJob(job);
This sample shows how to call CreateJob with all parameters.
Uri endpoint = new Uri("<https://my-service.azure.com>");
TokenCredential credential = new DefaultAzureCredential();
BatchClient client = new BatchClient(endpoint, credential);
BatchJobCreateContent job = new BatchJobCreateContent("<id>", new BatchPoolInfo
{
PoolId = "<poolId>",
AutoPoolSpecification = new BatchAutoPoolSpecification(BatchPoolLifetimeOption.JobSchedule)
{
AutoPoolIdPrefix = "<autoPoolIdPrefix>",
KeepAlive = true,
Pool = new BatchPoolSpecification("<vmSize>")
{
DisplayName = "<displayName>",
VirtualMachineConfiguration = new VirtualMachineConfiguration(new ImageReference
{
Publisher = "<publisher>",
Offer = "<offer>",
Sku = "<sku>",
Version = "<version>",
VirtualMachineImageId = "<virtualMachineImageId>",
}, "<nodeAgentSKUId>")
{
WindowsConfiguration = new WindowsConfiguration
{
EnableAutomaticUpdates = true,
},
DataDisks = {new DataDisk(1234, 1234)
{
Caching = CachingType.None,
StorageAccountType = StorageAccountType.StandardLRS,
}},
LicenseType = "<licenseType>",
ContainerConfiguration = new ContainerConfiguration(ContainerType.DockerCompatible)
{
ContainerImageNames = { "<containerImageNames>" },
ContainerRegistries = { default },
},
DiskEncryptionConfiguration = new DiskEncryptionConfiguration
{
Targets = { DiskEncryptionTarget.OsDisk },
},
NodePlacementConfiguration = new BatchNodePlacementConfiguration
{
Policy = BatchNodePlacementPolicyType.Regional,
},
Extensions = {new VMExtension("<name>", "<publisher>", "<type>")
{
TypeHandlerVersion = "<typeHandlerVersion>",
AutoUpgradeMinorVersion = true,
EnableAutomaticUpgrade = true,
Settings =
{
["key"] = "<settings>"
},
ProtectedSettings =
{
["key"] = "<protectedSettings>"
},
ProvisionAfterExtensions = {"<provisionAfterExtensions>"},
}},
OsDisk = new OSDisk
{
EphemeralOSDiskSettings = new DiffDiskSettings
{
Placement = DiffDiskPlacement.CacheDisk,
},
Caching = CachingType.None,
DiskSizeGB = 1234,
ManagedDisk = new ManagedDisk(StorageAccountType.StandardLRS),
WriteAcceleratorEnabled = true,
},
SecurityProfile = new SecurityProfile(true, SecurityTypes.TrustedLaunch, new UefiSettings
{
SecureBootEnabled = true,
VTpmEnabled = true,
}),
ServiceArtifactReference = new ServiceArtifactReference("<id>"),
},
TaskSlotsPerNode = 1234,
TaskSchedulingPolicy = new BatchTaskSchedulingPolicy(BatchNodeFillType.Spread),
ResizeTimeout = XmlConvert.ToTimeSpan("PT1H23M45S"),
ResourceTags = "<resourceTags>",
TargetDedicatedNodes = 1234,
TargetLowPriorityNodes = 1234,
EnableAutoScale = true,
AutoScaleFormula = "<autoScaleFormula>",
AutoScaleEvaluationInterval = XmlConvert.ToTimeSpan("PT1H23M45S"),
EnableInterNodeCommunication = true,
NetworkConfiguration = new NetworkConfiguration
{
SubnetId = "<subnetId>",
DynamicVNetAssignmentScope = DynamicVNetAssignmentScope.None,
EndpointConfiguration = new BatchPoolEndpointConfiguration(new InboundNatPool[]
{
new InboundNatPool("<name>", InboundEndpointProtocol.Tcp, 1234, 1234, 1234)
{
NetworkSecurityGroupRules = {new NetworkSecurityGroupRule(1234, NetworkSecurityGroupRuleAccess.Allow, "<sourceAddressPrefix>")
{
SourcePortRanges = {"<sourcePortRanges>"},
}},
}
}),
PublicIpAddressConfiguration = new PublicIpAddressConfiguration
{
IpAddressProvisioningType = IpAddressProvisioningType.BatchManaged,
IpAddressIds = { "<ipAddressIds>" },
},
EnableAcceleratedNetworking = true,
},
StartTask = new BatchStartTask("<commandLine>")
{
ContainerSettings = default,
ResourceFiles = { default },
EnvironmentSettings = { default },
UserIdentity = default,
MaxTaskRetryCount = 1234,
WaitForSuccess = true,
},
ApplicationPackageReferences = { default },
UserAccounts = {new UserAccount("<name>", "<password>")
{
ElevationLevel = ElevationLevel.NonAdmin,
LinuxUserConfiguration = new LinuxUserConfiguration
{
Uid = 1234,
Gid = 1234,
SshPrivateKey = "<sshPrivateKey>",
},
WindowsUserConfiguration = new WindowsUserConfiguration
{
LoginMode = LoginMode.Batch,
},
}},
Metadata = { new MetadataItem("<name>", "<value>") },
MountConfiguration = {new MountConfiguration
{
AzureBlobFileSystemConfiguration = new AzureBlobFileSystemConfiguration("<accountName>", "<containerName>", "<relativeMountPath>")
{
AccountKey = "<accountKey>",
SasKey = "<sasKey>",
BlobfuseOptions = "<blobfuseOptions>",
IdentityReference = default,
},
NfsMountConfiguration = new NfsMountConfiguration("<source>", "<relativeMountPath>")
{
MountOptions = "<mountOptions>",
},
CifsMountConfiguration = new CifsMountConfiguration("<username>", "<source>", "<relativeMountPath>", "<password>")
{
MountOptions = "<mountOptions>",
},
AzureFileShareConfiguration = new AzureFileShareConfiguration("<accountName>", "<azureFileUrl>", "<accountKey>", "<relativeMountPath>")
{
MountOptions = "<mountOptions>",
},
}},
TargetNodeCommunicationMode = BatchNodeCommunicationMode.Default,
UpgradePolicy = new UpgradePolicy(UpgradeMode.Automatic)
{
AutomaticOsUpgradePolicy = new AutomaticOsUpgradePolicy
{
DisableAutomaticRollback = true,
EnableAutomaticOsUpgrade = true,
UseRollingUpgradePolicy = true,
OsRollingUpgradeDeferral = true,
},
RollingUpgradePolicy = new RollingUpgradePolicy
{
EnableCrossZoneUpgrade = true,
MaxBatchInstancePercent = 1234,
MaxUnhealthyInstancePercent = 1234,
MaxUnhealthyUpgradedInstancePercent = 1234,
PauseTimeBetweenBatches = XmlConvert.ToTimeSpan("PT1H23M45S"),
PrioritizeUnhealthyInstances = true,
RollbackFailedInstancesOnPolicyBreach = true,
},
},
},
},
})
{
DisplayName = "<displayName>",
UsesTaskDependencies = true,
Priority = 1234,
AllowTaskPreemption = true,
MaxParallelTasks = 1234,
Constraints = new BatchJobConstraints
{
MaxWallClockTime = XmlConvert.ToTimeSpan("PT1H23M45S"),
MaxTaskRetryCount = 1234,
},
JobManagerTask = new BatchJobManagerTask("<id>", "<commandLine>")
{
DisplayName = "<displayName>",
ContainerSettings = new BatchTaskContainerSettings("<imageName>")
{
ContainerRunOptions = "<containerRunOptions>",
Registry = new ContainerRegistryReference
{
Username = "<username>",
Password = "<password>",
RegistryServer = "<registryServer>",
IdentityReference = new BatchNodeIdentityReference
{
ResourceId = "<resourceId>",
},
},
WorkingDirectory = ContainerWorkingDirectory.TaskWorkingDirectory,
},
ResourceFiles = {new ResourceFile
{
AutoStorageContainerName = "<autoStorageContainerName>",
StorageContainerUrl = "<storageContainerUrl>",
HttpUrl = "<httpUrl>",
BlobPrefix = "<blobPrefix>",
FilePath = "<filePath>",
FileMode = "<fileMode>",
IdentityReference = default,
}},
OutputFiles = {new OutputFile("<filePattern>", new OutputFileDestination
{
Container = new OutputFileBlobContainerDestination("<containerUrl>")
{
Path = "<path>",
IdentityReference = default,
UploadHeaders = {new HttpHeader("<name>")
{
Value = "<value>",
}},
},
}, new OutputFileUploadConfig(OutputFileUploadCondition.TaskSuccess))},
EnvironmentSettings = {new EnvironmentSetting("<name>")
{
Value = "<value>",
}},
Constraints = new BatchTaskConstraints
{
MaxWallClockTime = XmlConvert.ToTimeSpan("PT1H23M45S"),
RetentionTime = XmlConvert.ToTimeSpan("PT1H23M45S"),
MaxTaskRetryCount = 1234,
},
RequiredSlots = 1234,
KillJobOnCompletion = true,
UserIdentity = new UserIdentity
{
Username = "<username>",
AutoUser = new AutoUserSpecification
{
Scope = AutoUserScope.Task,
ElevationLevel = ElevationLevel.NonAdmin,
},
},
RunExclusive = true,
ApplicationPackageReferences = {new BatchApplicationPackageReference("<applicationId>")
{
Version = "<version>",
}},
AuthenticationTokenSettings = new AuthenticationTokenSettings
{
Access = { AccessScope.Job },
},
AllowLowPriorityNode = true,
},
JobPreparationTask = new BatchJobPreparationTask("<commandLine>")
{
Id = "<id>",
ContainerSettings = default,
ResourceFiles = { default },
EnvironmentSettings = { default },
Constraints = default,
WaitForSuccess = true,
UserIdentity = default,
RerunOnNodeRebootAfterSuccess = true,
},
JobReleaseTask = new BatchJobReleaseTask("<commandLine>")
{
Id = "<id>",
ContainerSettings = default,
ResourceFiles = { default },
EnvironmentSettings = { default },
MaxWallClockTime = XmlConvert.ToTimeSpan("PT1H23M45S"),
RetentionTime = XmlConvert.ToTimeSpan("PT1H23M45S"),
UserIdentity = default,
},
CommonEnvironmentSettings = { default },
OnAllTasksComplete = OnAllBatchTasksComplete.NoAction,
OnTaskFailure = OnBatchTaskFailure.NoAction,
NetworkConfiguration = new BatchJobNetworkConfiguration("<subnetId>"),
Metadata = { default },
};
Response response = client.CreateJob(job, timeOutInSeconds: 1234, ocpdate: DateTimeOffset.Parse("Tue, 10 May 2022 18:57:31 GMT"));
Remarks
The Batch service supports two ways to control the work done as part of a Job. In the first approach, the user specifies a Job Manager Task. The Batch service launches this Task when it is ready to start the Job. The Job Manager Task controls all other Tasks that run under this Job, by using the Task APIs. In the second approach, the user directly controls the execution of Tasks under an active Job, by using the Task APIs. Also note: when naming Jobs, avoid including sensitive information such as user names or secret project names. This information may appear in telemetry logs accessible to Microsoft Support engineers.
Applies to
CreateJob(RequestContent, Nullable<Int32>, Nullable<DateTimeOffset>, RequestContext)
- Source:
- BatchClient.cs
[Protocol Method] Creates a Job to the specified Account.
- This protocol method allows explicit creation of the request and processing of the response for advanced scenarios.
- Please try the simpler CreateJob(BatchJobCreateContent, Nullable<Int32>, Nullable<DateTimeOffset>, CancellationToken) convenience overload with strongly typed models first.
public virtual Azure.Response CreateJob (Azure.Core.RequestContent content, int? timeOutInSeconds = default, DateTimeOffset? ocpdate = default, Azure.RequestContext context = default);
abstract member CreateJob : Azure.Core.RequestContent * Nullable<int> * Nullable<DateTimeOffset> * Azure.RequestContext -> Azure.Response
override this.CreateJob : Azure.Core.RequestContent * Nullable<int> * Nullable<DateTimeOffset> * Azure.RequestContext -> Azure.Response
Public Overridable Function CreateJob (content As RequestContent, Optional timeOutInSeconds As Nullable(Of Integer) = Nothing, Optional ocpdate As Nullable(Of DateTimeOffset) = Nothing, Optional context As RequestContext = Nothing) As Response
Parameters
- content
- RequestContent
The content to send as the body of the request.
The maximum time that the server can spend processing the request, in seconds. The default is 30 seconds. If the value is larger than 30, the default will be used instead.".
- ocpdate
- Nullable<DateTimeOffset>
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.
- context
- RequestContext
The request context, which can override default behaviors of the client pipeline on a per-call basis.
Returns
The response returned from the service.
Exceptions
content
is null.
Service returned a non-success status code.
Examples
This sample shows how to call CreateJob.
Uri endpoint = new Uri("<https://my-service.azure.com>");
TokenCredential credential = new DefaultAzureCredential();
BatchClient client = new BatchClient(endpoint, credential);
using RequestContent content = RequestContent.Create(new
{
id = "<id>",
poolInfo = new object(),
});
Response response = client.CreateJob(content);
Console.WriteLine(response.Status);
This sample shows how to call CreateJob with all parameters and request content.
Uri endpoint = new Uri("<https://my-service.azure.com>");
TokenCredential credential = new DefaultAzureCredential();
BatchClient client = new BatchClient(endpoint, credential);
using RequestContent content = RequestContent.Create(new
{
id = "<id>",
displayName = "<displayName>",
usesTaskDependencies = true,
priority = 1234,
allowTaskPreemption = true,
maxParallelTasks = 1234,
constraints = new
{
maxWallClockTime = "PT1H23M45S",
maxTaskRetryCount = 1234,
},
jobManagerTask = new
{
id = "<id>",
displayName = "<displayName>",
commandLine = "<commandLine>",
containerSettings = new
{
containerRunOptions = "<containerRunOptions>",
imageName = "<imageName>",
registry = new
{
username = "<username>",
password = "<password>",
registryServer = "<registryServer>",
identityReference = new
{
resourceId = "<resourceId>",
},
},
workingDirectory = "taskWorkingDirectory",
},
resourceFiles = new object[]
{
new
{
autoStorageContainerName = "<autoStorageContainerName>",
storageContainerUrl = "<storageContainerUrl>",
httpUrl = "<httpUrl>",
blobPrefix = "<blobPrefix>",
filePath = "<filePath>",
fileMode = "<fileMode>",
}
},
outputFiles = new object[]
{
new
{
filePattern = "<filePattern>",
destination = new
{
container = new
{
path = "<path>",
containerUrl = "<containerUrl>",
uploadHeaders = new object[]
{
new
{
name = "<name>",
value = "<value>",
}
},
},
},
uploadOptions = new
{
uploadCondition = "tasksuccess",
},
}
},
environmentSettings = new object[]
{
new
{
name = "<name>",
value = "<value>",
}
},
constraints = new
{
maxWallClockTime = "PT1H23M45S",
retentionTime = "PT1H23M45S",
maxTaskRetryCount = 1234,
},
requiredSlots = 1234,
killJobOnCompletion = true,
userIdentity = new
{
username = "<username>",
autoUser = new
{
scope = "task",
elevationLevel = "nonadmin",
},
},
runExclusive = true,
applicationPackageReferences = new object[]
{
new
{
applicationId = "<applicationId>",
version = "<version>",
}
},
authenticationTokenSettings = new
{
access = new object[]
{
"job"
},
},
allowLowPriorityNode = true,
},
jobPreparationTask = new
{
id = "<id>",
commandLine = "<commandLine>",
resourceFiles = new object[]
{
null
},
environmentSettings = new object[]
{
null
},
waitForSuccess = true,
rerunOnNodeRebootAfterSuccess = true,
},
jobReleaseTask = new
{
id = "<id>",
commandLine = "<commandLine>",
resourceFiles = new object[]
{
null
},
environmentSettings = new object[]
{
null
},
maxWallClockTime = "PT1H23M45S",
retentionTime = "PT1H23M45S",
},
commonEnvironmentSettings = new object[]
{
null
},
poolInfo = new
{
poolId = "<poolId>",
autoPoolSpecification = new
{
autoPoolIdPrefix = "<autoPoolIdPrefix>",
poolLifetimeOption = "jobschedule",
keepAlive = true,
pool = new
{
displayName = "<displayName>",
vmSize = "<vmSize>",
virtualMachineConfiguration = new
{
imageReference = new
{
publisher = "<publisher>",
offer = "<offer>",
sku = "<sku>",
version = "<version>",
virtualMachineImageId = "<virtualMachineImageId>",
},
nodeAgentSKUId = "<nodeAgentSKUId>",
windowsConfiguration = new
{
enableAutomaticUpdates = true,
},
dataDisks = new object[]
{
new
{
lun = 1234,
caching = "none",
diskSizeGB = 1234,
storageAccountType = "standard_lrs",
}
},
licenseType = "<licenseType>",
containerConfiguration = new
{
type = "dockerCompatible",
containerImageNames = new object[]
{
"<containerImageNames>"
},
containerRegistries = new object[]
{
null
},
},
diskEncryptionConfiguration = new
{
targets = new object[]
{
"osdisk"
},
},
nodePlacementConfiguration = new
{
policy = "regional",
},
extensions = new object[]
{
new
{
name = "<name>",
publisher = "<publisher>",
type = "<type>",
typeHandlerVersion = "<typeHandlerVersion>",
autoUpgradeMinorVersion = true,
enableAutomaticUpgrade = true,
settings = new
{
key = "<settings>",
},
protectedSettings = new
{
key = "<protectedSettings>",
},
provisionAfterExtensions = new object[]
{
"<provisionAfterExtensions>"
},
}
},
osDisk = new
{
ephemeralOSDiskSettings = new
{
placement = "cachedisk",
},
caching = "none",
diskSizeGB = 1234,
managedDisk = new
{
storageAccountType = "standard_lrs",
},
writeAcceleratorEnabled = true,
},
securityProfile = new
{
encryptionAtHost = true,
securityType = "trustedLaunch",
uefiSettings = new
{
secureBootEnabled = true,
vTpmEnabled = true,
},
},
serviceArtifactReference = new
{
id = "<id>",
},
},
taskSlotsPerNode = 1234,
taskSchedulingPolicy = new
{
nodeFillType = "spread",
},
resizeTimeout = "PT1H23M45S",
resourceTags = "<resourceTags>",
targetDedicatedNodes = 1234,
targetLowPriorityNodes = 1234,
enableAutoScale = true,
autoScaleFormula = "<autoScaleFormula>",
autoScaleEvaluationInterval = "PT1H23M45S",
enableInterNodeCommunication = true,
networkConfiguration = new
{
subnetId = "<subnetId>",
dynamicVNetAssignmentScope = "none",
endpointConfiguration = new
{
inboundNATPools = new object[]
{
new
{
name = "<name>",
protocol = "tcp",
backendPort = 1234,
frontendPortRangeStart = 1234,
frontendPortRangeEnd = 1234,
networkSecurityGroupRules = new object[]
{
new
{
priority = 1234,
access = "allow",
sourceAddressPrefix = "<sourceAddressPrefix>",
sourcePortRanges = new object[]
{
"<sourcePortRanges>"
},
}
},
}
},
},
publicIPAddressConfiguration = new
{
provision = "batchmanaged",
ipAddressIds = new object[]
{
"<ipAddressIds>"
},
},
enableAcceleratedNetworking = true,
},
startTask = new
{
commandLine = "<commandLine>",
resourceFiles = new object[]
{
null
},
environmentSettings = new object[]
{
null
},
maxTaskRetryCount = 1234,
waitForSuccess = true,
},
applicationPackageReferences = new object[]
{
null
},
userAccounts = new object[]
{
new
{
name = "<name>",
password = "<password>",
elevationLevel = "nonadmin",
linuxUserConfiguration = new
{
uid = 1234,
gid = 1234,
sshPrivateKey = "<sshPrivateKey>",
},
windowsUserConfiguration = new
{
loginMode = "batch",
},
}
},
metadata = new object[]
{
new
{
name = "<name>",
value = "<value>",
}
},
mountConfiguration = new object[]
{
new
{
azureBlobFileSystemConfiguration = new
{
accountName = "<accountName>",
containerName = "<containerName>",
accountKey = "<accountKey>",
sasKey = "<sasKey>",
blobfuseOptions = "<blobfuseOptions>",
relativeMountPath = "<relativeMountPath>",
},
nfsMountConfiguration = new
{
source = "<source>",
relativeMountPath = "<relativeMountPath>",
mountOptions = "<mountOptions>",
},
cifsMountConfiguration = new
{
username = "<username>",
source = "<source>",
relativeMountPath = "<relativeMountPath>",
mountOptions = "<mountOptions>",
password = "<password>",
},
azureFileShareConfiguration = new
{
accountName = "<accountName>",
azureFileUrl = "<azureFileUrl>",
accountKey = "<accountKey>",
relativeMountPath = "<relativeMountPath>",
mountOptions = "<mountOptions>",
},
}
},
targetNodeCommunicationMode = "default",
upgradePolicy = new
{
mode = "automatic",
automaticOSUpgradePolicy = new
{
disableAutomaticRollback = true,
enableAutomaticOSUpgrade = true,
useRollingUpgradePolicy = true,
osRollingUpgradeDeferral = true,
},
rollingUpgradePolicy = new
{
enableCrossZoneUpgrade = true,
maxBatchInstancePercent = 1234,
maxUnhealthyInstancePercent = 1234,
maxUnhealthyUpgradedInstancePercent = 1234,
pauseTimeBetweenBatches = "PT1H23M45S",
prioritizeUnhealthyInstances = true,
rollbackFailedInstancesOnPolicyBreach = true,
},
},
},
},
},
onAllTasksComplete = "noaction",
onTaskFailure = "noaction",
networkConfiguration = new
{
subnetId = "<subnetId>",
},
metadata = new object[]
{
null
},
});
Response response = client.CreateJob(content, timeOutInSeconds: 1234, ocpdate: DateTimeOffset.Parse("Tue, 10 May 2022 18:57:31 GMT"));
Console.WriteLine(response.Status);