@@ -51,6 +51,9 @@ Write-Host "Retrieved $ssm_config_path/enable_cloudwatch parameter - ($enable_c
51
51
$agent_mode = $parameters.where ( {$_.Name -eq " $ssm_config_path /agent_mode" }).value
52
52
Write-Host " Retrieved $ssm_config_path /agent_mode parameter - ($agent_mode )"
53
53
54
+ $enable_jit_config = $parameters.where ( {$_.Name -eq " $ssm_config_path /enable_jit_config" }).value
55
+ Write-Host " Retrieved $ssm_config_path /enable_jit_config parameter - ($enable_jit_config )"
56
+
54
57
$token_path = $parameters.where ( {$_.Name -eq " $ssm_config_path /token_path" }).value
55
58
Write-Host " Retrieved $ssm_config_path /token_path parameter - ($token_path )"
56
59
@@ -107,11 +110,11 @@ foreach ($group in @("Administrators", "docker-users")) {
107
110
Set-ItemProperty HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System - Name ConsentPromptBehaviorAdmin - Value 0 - Force
108
111
Write-Host " Disabled User Access Control (UAC)"
109
112
110
- $configCmd = " .\config.cmd --unattended --name $runner_name_prefix$InstanceId --work `" _work `" $config "
111
- Write-Host " Configure GH Runner as user $run_as "
112
- Invoke-Expression $configCmd
113
-
114
- Write-Host " Starting the runner as user $run_as "
113
+ if ( $enable_jit_config -eq " false " -or $agent_mode -ne " ephemeral " ) {
114
+ $configCmd = " .\config.cmd --unattended --name $runner_name_prefix$InstanceId --work `" _work `" $config "
115
+ Write-Host " Configure GH Runner (non ephmeral / no JIT) as user $run_as "
116
+ Invoke-Expression $configCmd
117
+ }
115
118
116
119
$jsonBody = @ (
117
120
@ {
@@ -121,10 +124,34 @@ $jsonBody = @(
121
124
)
122
125
ConvertTo-Json - InputObject $jsonBody | Set-Content - Path " $pwd \.setup_info"
123
126
124
- Write-Host " Installing the runner as a service"
125
127
126
- $action = New-ScheduledTaskAction - WorkingDirectory " $pwd " - Execute " run.cmd"
127
- $trigger = Get-CimClass " MSFT_TaskRegistrationTrigger" - Namespace " Root/Microsoft/Windows/TaskScheduler"
128
- Register-ScheduledTask - TaskName " runnertask" - Action $action - Trigger $trigger - User $username - Password $password - RunLevel Highest - Force
129
- Write-Host " Starting the runner in persistent mode"
128
+ Write-Host " Starting the runner in $agent_mode mode"
130
129
Write-Host " Starting runner after $ ( ((get-date ) - (gcim Win32_OperatingSystem).LastBootUpTime).tostring(" hh':'mm':'ss''" )) "
130
+
131
+ if ($agent_mode -eq " ephemeral" ) {
132
+ if ($enable_jit_config -eq " true" ) {
133
+ Write-Host " Starting with jit config"
134
+ Invoke-Expression " .\run.cmd --jitconfig $$ {config}"
135
+ }
136
+ else {
137
+ Write-Host " Starting without jit config"
138
+ Invoke-Expression " .\run.cmd"
139
+ }
140
+ Write-Host " Runner has finished"
141
+
142
+ if ($enable_cloudwatch_agent )
143
+ {
144
+ Write-Host " Stopping CloudWatch Agent"
145
+ & ' C:\Program Files\Amazon\AmazonCloudWatchAgent\amazon-cloudwatch-agent-ctl.ps1' - a stop
146
+ }
147
+
148
+ Write-Host " Terminating instance"
149
+ aws ec2 terminate- instances -- instance- ids " $InstanceId " -- region " $Region "
150
+ } else {
151
+ Write-Host " Installing the runner as a service"
152
+
153
+ $action = New-ScheduledTaskAction - WorkingDirectory " $pwd " - Execute " run.cmd"
154
+ $trigger = Get-CimClass " MSFT_TaskRegistrationTrigger" - Namespace " Root/Microsoft/Windows/TaskScheduler"
155
+ Register-ScheduledTask - TaskName " runnertask" - Action $action - Trigger $trigger - User $username - Password $password - RunLevel Highest - Force
156
+ Write-Host " Starting runner after $ ( ((get-date ) - (gcim Win32_OperatingSystem).LastBootUpTime).tostring(" hh':'mm':'ss''" )) "
157
+ }
0 commit comments