-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbatchjob.ps1
31 lines (30 loc) · 1.27 KB
/
batchjob.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# Local path where the solution files are saved
$path = "C:\projects\github\azbatch\"
$paramfile = $path + "batchjob.parameters.json"
$params = get-content $paramfile | ConvertFrom-Json
$prefix = $params.deploymentPrefix
$accountname = $prefix + "batch"
$poolname = $params.poolname
$jobid = $params.jobid
# Get Batch context
$context = Get-AzBatchAccount -AccountName $accountname
# Create Jobs
$PoolInformation = New-Object -TypeName "Microsoft.Azure.Commands.Batch.Models.PSPoolInformation"
$PoolInformation.PoolId = $poolname
# -- job may have -JobPreparationTask
New-AzBatchJob -Id $jobid -PoolInformation $PoolInformation -BatchContext $context -UsesTaskDependencies
# Create Tasks
$alltasks = $params.tasks
$alltasks | ForEach-Object {
$task = New-Object Microsoft.Azure.Commands.Batch.Models.PSCloudTask($_.id, $_.command)
# with dependencies, if any
if($null -ne $_.dependencies -and $_.dependencies.lenght -gt 0){
$dependencies = [string[]]@()
$_.dependencies | ForEach-Object {
$dependencies += $_.id
}
$task.DependsOn = New-Object Microsoft.Azure.Commands.Batch.Models.PSTaskDependencies($dependencies,$null)
}
New-AzBatchTask -JobId $jobid -Tasks @($task) -BatchContext $context
}
Write-Output "Job with Tasks Submitted"