The before_script starts a ssh-agent which is used by the script to copy some files via rsync to a remote server.
I want the after_script to stop the agent. But it seems like the environment is reset after the script has run.
The script has access to the environment and is able to sync files using the previously started ssh-agent.
As it is unable to stop the ssh-agent the processes pile up from build to build wasting resources.
We’ve identified (a lot of “echo $$”) that „before_script” and the actual stage is ran in the same shell session but the „after_script” is ran in another shell session.
I think this is clearly a small bug.
We’ve managed to do it by writing the pid of the ssh-agent in a file:
echo SSH_AGENT_PID > /tmp/agent-{CI_JOB_ID}
And in after_script we kill the pid from that file.