Skip to content

Commit 197beb6

Browse files
committed
start-runner.ps1 set username
1 parent 92710de commit 197beb6

File tree

1 file changed

+16
-17
lines changed

1 file changed

+16
-17
lines changed

modules/runners/templates/start-runner.ps1

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -177,30 +177,29 @@ ConvertTo-Json -InputObject $jsonBody | Set-Content -Path "$pwd\.setup_info"
177177
Write-Host "Starting the runner in $agent_mode mode"
178178
Write-Host "Starting runner after $(((get-date) - (gcim Win32_OperatingSystem).LastBootUpTime).tostring("hh':'mm':'ss''"))"
179179

180+
$taskExecutable = "run.cmd"
181+
$taskArgument = $null
182+
180183
if ($agent_mode -eq "ephemeral") {
181184
if ($enable_jit_config -eq "true") {
182185
Write-Host "Starting with jit config"
183-
Invoke-Expression ".\run.cmd --jitconfig $${config}"
186+
$taskExecutable = "run.cmd"
187+
$taskArgument = "--jitconfig $${config}"
184188
}
185189
else {
186190
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"
195192
}
193+
}
196194

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"
201196

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"
206202
}
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

Comments
 (0)