Skip to content

Commit

Permalink
fix: Linux agents are not deleted from server history
Browse files Browse the repository at this point in the history
  • Loading branch information
clemlesne committed Mar 25, 2024
1 parent 3dd390e commit c8288f2
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
25 changes: 24 additions & 1 deletion src/docker/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,23 @@ write_header() {
echo -e "${lightcyan}➡️ $1${nocolor}"
}

unregister() {
write_header "Unregister, removing agent from server..."

# If the agent has some running jobs, the configuration removal process will fail ; so, give it some time to finish the job
while true; do
# If the agent is removed successfully, exit the loop
bash config.sh remove \
--auth PAT \
--token "$$AZP_TOKEN" \
--unattended \
&& break

echo "Retrying in 15 secs..."
sleep 15
done
}

if [ -d "$AZP_CUSTOM_CERT_PEM" ] && [ "$(ls -A $AZP_CUSTOM_CERT_PEM)" ]; then
write_header "Adding custom SSL certificates..."
echo "Searching for *.crt in $AZP_CUSTOM_CERT_PEM"
Expand Down Expand Up @@ -100,7 +117,13 @@ bash config.sh \
# See: https://stackoverflow.com/a/62183992/12732154
wait $!

print_header "Running agent..."
# Unregister on success
trap 'unregister; exit 0' EXIT
# Unregister on Ctrl+C
trap 'unregister; exit 130' INT
# Unregister on SIGTERM
trap 'unregister; exit 143' TERM

write_header "Running agent..."

# Running it with the --once flag at the end will shut down the agent after the build is executed
Expand Down
6 changes: 1 addition & 5 deletions src/helm/azure-pipelines-agent/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -157,14 +157,10 @@ containers:
# For security reasons, force clean the pipeline workspace at restart -- Sharing data bewteen pipelines is a security risk
Remove-Item -Recurse -Force $Env:AZP_WORK;
{{- end }}
{{- else }}
{{- else not .Values.pipelines.cache.volumeEnabled or not .Values.pipelines.tmpdir.volumeEnabled}}
- bash
- -c
- |
bash config.sh \
remove \
--auth PAT \
--token ${AZP_TOKEN};
{{- if not .Values.pipelines.cache.volumeEnabled }}
# For security reasons, force clean the pipeline workspace at restart -- Sharing data bewteen pipelines is a security risk
rm -rf ${AZP_WORK};
Expand Down

0 comments on commit c8288f2

Please sign in to comment.