Skip to content

Commit d72ac8f

Browse files
committed
Disable interpolation of HEREDOC strings containing hook scripts
Interpolation was applied within the user-data.sh context, causing unexpected empty values for variables and other unintentend effects. While this behavior might be useful in certain cases, it requires consistently escaping everything in hook scripts. This approach feels error-prone and unintuitive. For example, the following configuration will echo an empty string and the date of string interpolation, but not the date of the job's start: ``` runner_hook_job_started: | echo $GITHUB_WORKSPACE echo $(date) ```
1 parent fbac69a commit d72ac8f

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

examples/multi-runner/templates/user-data.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -82,14 +82,14 @@ ${post_install}
8282
cd /opt/actions-runner
8383

8484
%{ if hook_job_started != "" }
85-
cat > /opt/actions-runner/hook_job_started.sh << EOF
85+
cat > /opt/actions-runner/hook_job_started.sh <<'EOF'
8686
${hook_job_started}
8787
EOF
8888
echo ACTIONS_RUNNER_HOOK_JOB_STARTED=/opt/actions-runner/hook_job_started.sh | tee -a /opt/actions-runner/.env
8989
%{ endif }
9090

9191
%{ if hook_job_completed != "" }
92-
cat > /opt/actions-runner/hook_job_completed.sh << EOF
92+
cat > /opt/actions-runner/hook_job_completed.sh <<'EOF'
9393
${hook_job_completed}
9494
EOF
9595
echo ACTIONS_RUNNER_HOOK_JOB_COMPLETED=/opt/actions-runner/hook_job_completed.sh | tee -a /opt/actions-runner/.env

modules/runners/templates/user-data.sh

+3-3
Original file line numberDiff line numberDiff line change
@@ -63,16 +63,16 @@ ${install_runner}
6363
${post_install}
6464

6565
# Register runner job hooks
66-
# Ref: https://github.com/actions/runner/blob/main/docs/adrs/1751-runner-job-hooks.md
66+
# Ref: https://docs.github.com/en/actions/hosting-your-own-runners/managing-self-hosted-runners/running-scripts-before-or-after-a-job
6767
%{ if hook_job_started != "" }
68-
cat > /opt/actions-runner/hook_job_started.sh << EOF
68+
cat > /opt/actions-runner/hook_job_started.sh <<'EOF'
6969
${hook_job_started}
7070
EOF
7171
echo ACTIONS_RUNNER_HOOK_JOB_STARTED=/opt/actions-runner/hook_job_started.sh | tee -a /opt/actions-runner/.env
7272
%{ endif }
7373

7474
%{ if hook_job_completed != "" }
75-
cat > /opt/actions-runner/hook_job_completed.sh << EOF
75+
cat > /opt/actions-runner/hook_job_completed.sh <<'EOF'
7676
${hook_job_completed}
7777
EOF
7878
echo ACTIONS_RUNNER_HOOK_JOB_COMPLETED=/opt/actions-runner/hook_job_completed.sh | tee -a /opt/actions-runner/.env

0 commit comments

Comments
 (0)