From 23638e0773fb3f0f4f92ea14b0d93d5bdd663490 Mon Sep 17 00:00:00 2001
From: nrb <freifunk@nicoboehr.de>
Date: Sun, 26 Sep 2021 19:30:16 +0200
Subject: [PATCH] gitlab-ci: start the SSH agent again in after_script

The git push in after_script didn't succeed because of failing
authentication. As the authentication succeeds in before_script, it is
likely the SSH agent from before_script doesn't run in after_script.
Likely because a new shell is spawned. Hence, start it again in
after_script.
---
 .gitlab-ci.yml | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 756859003..f6dc35946 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -25,7 +25,16 @@ default:
     - rm -rf gluon/openwrt/dl && mkdir -p gluon/openwrt && ln -s ../../ffs-openwrt-dl-cache gluon/openwrt/dl
     - rm -rf gluon/openwrt/staging_dir && mkdir -p staging_dir && ln -s ../../staging_dir gluon/openwrt/staging_dir
   after_script:
-    - cd gluon/openwrt/dl && git add . && git commit -m "update DL cache" && git push || true
+    # we need to start the SSH agent again because it doesn't seem to stay running
+    - 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )'
+    - eval $(ssh-agent -s)
+    - ssh-add <(echo "$GIT_SSH_PRIV_KEY")
+    - git config --global user.email "firmware@freifunk-stuttgart.de"
+    - git config --global user.name "FFS Buildbot"
+    - mkdir -p ~/.ssh
+    - cat gitlab-known-hosts >> ~/.ssh/known_hosts
+    - cd gluon/openwrt/dl && git add . && git commit -m "update DL cache" || true
+    - git push || true
 
 generate_date:
   stage: generate_date
-- 
GitLab