I have a similar problem.
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.
The deploy job:
- 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )'
- eval $(ssh-agent -s)
- ssh-add <(echo "$SSH_PRIVATE_KEY")
- mkdir -p ~/.ssh
- echo -e "Host remotehost\nHostName remotehost\nCompression yes\nUser deployer\n\n" > ~/.ssh/config
- ./gradlew -Penv=test publish --stacktrace --info
- ssh-agent -k
Running with gitlab-ci-multi-runner 1.5.2 (76fdacd)
Using Shell executor...
Running on zweiblum...
HEAD ist jetzt bei c4442b5 kill the damn agent....
Checking out c4442b55 as develop...
Checking cache for deploy_dev/develop...
Downloading artifacts for build_dev (61)...
Downloading artifacts from coordinator... ok id=61 responseStatus=200 OK token=shU-FXJr
$ which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )
$ eval $(ssh-agent -s)
Agent pid 32699
$ ssh-add <(echo "$SSH_PRIVATE_KEY")
Identity added: /dev/fd/63 (rsa w/o comment)
$ mkdir -p ~/.ssh
$ echo -e "Host remotehost\nHostName remotehost\nCompression yes\nUser deployer\n\n" > ~/.ssh/config
$ ./gradlew -Penv=test publish --stacktrace --info
Total time: 18.177 secs
Running after script...
$ ssh-agent -k
SSH_AGENT_PID not set, cannot kill agent