@@ -177,30 +177,29 @@ ConvertTo-Json -InputObject $jsonBody | Set-Content -Path "$pwd\.setup_info"
177
177
Write-Host " Starting the runner in $agent_mode mode"
178
178
Write-Host " Starting runner after $ ( ((get-date ) - (gcim Win32_OperatingSystem).LastBootUpTime).tostring(" hh':'mm':'ss''" )) "
179
179
180
+ $taskExecutable = " run.cmd"
181
+ $taskArgument = $null
182
+
180
183
if ($agent_mode -eq " ephemeral" ) {
181
184
if ($enable_jit_config -eq " true" ) {
182
185
Write-Host " Starting with jit config"
183
- Invoke-Expression " .\run.cmd --jitconfig $$ {config}"
186
+ $taskExecutable = " run.cmd"
187
+ $taskArgument = " --jitconfig $$ {config}"
184
188
}
185
189
else {
186
190
Write-Host " Starting without jit config"
187
- Invoke-Expression " .\run.cmd"
188
- }
189
- Write-Host " Runner has finished"
190
-
191
- if ($enable_cloudwatch_agent )
192
- {
193
- Write-Host " Stopping CloudWatch Agent"
194
- & ' C:\Program Files\Amazon\AmazonCloudWatchAgent\amazon-cloudwatch-agent-ctl.ps1' - a stop
191
+ $taskExecutable = " run.cmd"
195
192
}
193
+ }
196
194
197
- Write-Host " Terminating instance"
198
- aws ec2 terminate- instances -- instance- ids " $InstanceId " -- region " $Region "
199
- } else {
200
- Write-Host " Installing the runner as a service"
195
+ Write-Host " Installing the runner as a service"
201
196
202
- $action = New-ScheduledTaskAction - WorkingDirectory " $pwd " - Execute " run.cmd"
203
- $trigger = Get-CimClass " MSFT_TaskRegistrationTrigger" - Namespace " Root/Microsoft/Windows/TaskScheduler"
204
- Register-ScheduledTask - TaskName " runnertask" - Action $action - Trigger $trigger - User $username - Password $password - RunLevel Highest - Force
205
- Write-Host " Starting runner after $ ( ((get-date ) - (gcim Win32_OperatingSystem).LastBootUpTime).tostring(" hh':'mm':'ss''" )) "
197
+ if ( $taskArgument ) {
198
+ $action = New-ScheduledTaskAction - WorkingDirectory " $pwd " - Execute " $taskExecutable " - Argument " $taskArgument "
199
+ }
200
+ else {
201
+ $action = New-ScheduledTaskAction - WorkingDirectory " $pwd " - Execute " $taskExecutable "
206
202
}
203
+ $trigger = Get-CimClass " MSFT_TaskRegistrationTrigger" - Namespace " Root/Microsoft/Windows/TaskScheduler"
204
+ Register-ScheduledTask - TaskName " runnertask" - Action $action - Trigger $trigger - User $username - Password $password - RunLevel Highest - Force
205
+ Write-Host " Starting runner after $ ( ((get-date ) - (gcim Win32_OperatingSystem).LastBootUpTime).tostring(" hh':'mm':'ss''" )) "
0 commit comments