Shell script traps dont fire
Summary
Adding traps to the CI script should ensure those will get executed. With Gitlab CI there seems to be an regression since 10.3 where this is not happening.
Steps to reproduce
Make a CI Project and setup some traps, a example .gitlab-ci.yml
follows:
firmware:
stage: build
script:
- '#!/bin/sh -e'
- set -e
- 'TEMPDIR=$(mktemp -d) && trap "echo DELTERM; rm -rf $TEMPDIR; trap - TERM; kill -TERM $$" TERM; trap "echo DELINT; rm -rf $TEMPDIR; trap - INT; kill -INT $$" INT; trap "echo DEL0; rm -rf $TEMPDIR" 0'
Note
Example Project
https://gitlab.com/nolange/reproduce_traps_not_executing
What is the current bug behavior?
Traps are not executed, and on our builder the TEMPDIR
directories are'nt deleted and ever increasing
What is the expected correct behavior?
Traps are executed, in the example project the messages should be displayed.
Relevant logs and/or screenshots
Note the missing output:
Running with gitlab-runner 10.3.0 (5cf5e19a)
on docker-auto-scale (4e4528ca)
Using Docker executor with image ruby:2.1 ...
Using docker image sha256:9153192958344879a5efcb4ce1f37fb20e1e9151d9a3aa4ace986b94457808ea for predefined container...
Pulling docker image ruby:2.1 ...
Using docker image ruby:2.1 ID=sha256:223d1eaa9523fa64e78f5a92b701c9c11cbc507f0ff62246dbbacdae395ffea3 for build container...
Running on runner-4e4528ca-project-5038863-concurrent-0 via runner-4e4528ca-srm-1514888684-356fd930...
Cloning repository...
Cloning into '/builds/nolange/reproduce_traps_not_executing'...
Checking out ea13c814 as master...
Skipping Git submodules setup
$ #!/bin/sh -e
$ set -e
$ TEMPDIR=$(mktemp -d) && trap "echo DELTERM; rm -rf $TEMPDIR; trap - TERM; kill -TERM $$" TERM; trap "echo DELINT; rm -rf $TEMPDIR; trap - INT; kill -INT $$" INT; trap "echo DEL0; rm -rf $TEMPDIR" 0
Job succeeded
Results of GitLab environment info
(using docker image)
Expand for output related to GitLab environment info
System information System: Current User: git Using RVM: no Ruby Version: 2.3.5p376 Gem Version: 2.6.13 Bundler Version:1.13.7 Rake Version: 12.3.0 Redis Version: 3.2.11 Git Version: 2.14.3 Sidekiq Version:5.0.4 Go Version: unknown
GitLab information Version: 10.3.2 Revision: 5fbc5f2 Directory: /opt/gitlab/embedded/service/gitlab-rails DB Adapter: postgresql URL: http://10.99.11.2 HTTP Clone URL: http://10.99.11.2/some-group/some-project.git SSH Clone URL: git@10.99.11.2:some-group/some-project.git Using LDAP: no Using Omniauth: no
GitLab Shell Version: 5.10.2 Repository storage paths:
- default: /var/opt/gitlab/git-data/repositories Hooks: /opt/gitlab/embedded/service/gitlab-shell/hooks Git: /opt/gitlab/embedded/bin/git
Results of GitLab application Check
Expand for output related to the GitLab application check
System information System: Current User: git Using RVM: no Ruby Version: 2.3.5p376 Gem Version: 2.6.13 Bundler Version:1.13.7 Rake Version: 12.3.0 Redis Version: 3.2.11 Git Version: 2.14.3 Sidekiq Version:5.0.4 Go Version: unknownGitLab information Version: 10.3.2 Revision: 5fbc5f2 Directory: /opt/gitlab/embedded/service/gitlab-rails DB Adapter: postgresql URL: http://10.99.11.2 HTTP Clone URL: http://10.99.11.2/some-group/some-project.git SSH Clone URL: git@10.99.11.2:some-group/some-project.git Using LDAP: no Using Omniauth: no
GitLab Shell Version: 5.10.2 Repository storage paths:
- default: /var/opt/gitlab/git-data/repositories Hooks: /opt/gitlab/embedded/service/gitlab-shell/hooks Git: /opt/gitlab/embedded/bin/git root@72e0eaea823c:/# gitlab-rake gitlab:check SANITIZE=true Checking GitLab Shell ...
GitLab Shell version >= 5.10.2 ? ... OK (5.10.2) Repo base directory exists? default... yes Repo storage directories are symlinks? default... no Repo paths owned by git:root, or git:git? default... yes Repo paths access is drwxrws---? default... yes hooks directories in repos are links: ... 6/1 ... ok 6/3 ... ok 1/5 ... ok 2/6 ... ok 9/7 ... ok 1/8 ... ok 6/9 ... ok 6/10 ... ok 5/11 ... ok 6/12 ... ok 14/13 ... ok 14/14 ... ok 5/15 ... ok 16/16 ... ok 16/17 ... ok 15/20 ... ok 16/21 ... ok 16/22 ... ok 15/23 ... ok 16/24 ... ok 15/25 ... ok 15/26 ... ok 5/27 ... repository is empty 5/28 ... ok 15/29 ... ok Running /opt/gitlab/embedded/service/gitlab-shell/bin/check Check GitLab API access: OK Redis available via internal API: OK
Access to /var/opt/gitlab/.ssh/authorized_keys: OK gitlab-shell self-check successful
Checking GitLab Shell ... Finished
Checking Sidekiq ...
Running? ... yes Number of Sidekiq processes ... 1
Checking Sidekiq ... Finished
Reply by email is disabled in config/gitlab.yml Checking LDAP ...
LDAP is disabled in config/gitlab.yml
Checking LDAP ... Finished
Checking GitLab ...
Git configured correctly? ... yes Database config exists? ... yes All migrations up? ... yes Database contains orphaned GroupMembers? ... no GitLab config exists? ... yes GitLab config up to date? ... yes Log directory writable? ... yes Tmp directory writable? ... yes Uploads directory exists? ... yes Uploads directory has correct permissions? ... yes Uploads directory tmp has correct permissions? ... yes Init script exists? ... skipped (omnibus-gitlab has no init script) Init script up-to-date? ... skipped (omnibus-gitlab has no init script) Projects have namespace: ... 6/1 ... yes 6/3 ... yes 1/5 ... yes 2/6 ... yes 9/7 ... yes 1/8 ... yes 6/9 ... yes 6/10 ... yes 5/11 ... yes 6/12 ... yes 14/13 ... yes 14/14 ... yes 5/15 ... yes 16/16 ... yes 16/17 ... yes 15/20 ... yes 16/21 ... yes 16/22 ... yes 15/23 ... yes 16/24 ... yes 15/25 ... yes 15/26 ... yes 5/27 ... yes 5/28 ... yes 15/29 ... yes Redis version >= 2.8.0? ... yes Ruby version >= 2.3.5 ? ... yes (2.3.5) Git version >= 2.7.3 ? ... yes (2.14.3) Git user has default SSH configuration? ... no Try fixing it: mkdir ~/gitlab-check-backup-1514889317 sudo mv /var/opt/gitlab/.ssh/id_rsa ~/gitlab-check-backup-1514889317 sudo mv /var/opt/gitlab/.ssh/config ~/gitlab-check-backup-1514889317 sudo mv /var/opt/gitlab/.ssh/id_rsa.pub ~/gitlab-check-backup-1514889317 For more information see: doc/ssh/README.md in section "SSH on the GitLab server" Please fix the error above and rerun the checks. Active users: ... 13
Checking GitLab ... Finished