gitlab-ci does not execute scripts correctly

Summary

.gitlab-ci.yml cannot execute bash script.

Steps to reproduce

I've created a MWE.

In the .gitlab-ci.yml file, enter this:

build:
    script:
        - git diff HEAD^ HEAD --name-only
        - bash simplescript.sh backend

In the root of the project, create the file simplescript.sh with the content:

#!/usr/bin/env bash
echo "Hello from the simple script"
echo "${1}"
cmd="git diff HEAD^ HEAD --name-only"
echo "Execute ${cmd}"
which find
find / -name "*git" -type f
which git
git --version
git diff HEAD^ HEAD --name-only
${cmd}

What is the current bug behavior?

The current bug is that this fails. I get the following output from the runner

Running with gitlab-runner 10.0.2 (a9a76a50)
  on dev1.company.com (8c3a0808)
Using Shell executor...
Running on dev1.company.com...
Fetching changes...
HEAD is now at 5fec64b poop
From http://dev1.company.com/Group1/Project-migration-test
   5fec64b..5937465  master     -> origin/master
Checking out 59374655 as master...
Skipping Git submodules setup
$ git diff HEAD^ HEAD --name-only
.gitlab-ci.yml
simplescript.sh
$ bash simplescript.sh backend
Hello from the simple script
backend
Execute git diff HEAD^ HEAD --name-only

which: no find
 in (/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/home/gitlab-runner/.local/bin:/home/gitlab-runner/bin)
find: Arguments to -type should contain only one letter
which: no git
 in (/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/home/gitlab-runner/.local/bin:/home/gitlab-runner/bin)
Unknown option: --version
usage: git [--version] [--help] [-c name=value]
           [--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]
           [-p|--paginate|--no-pager] [--no-replace-objects] [--bare]
           [--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]
           <command> [<args>]
usage: git diff [<options>] [<commit> [<commit>]] [--] [<path>...]
usage: git diff [<options>] [<commit> [<commit>]] [--] [<path>...]
ERROR: Job failed: exit status 1

What is the expected correct behavior?

I would expect something like this, which I get on my local machine

% bash simplescript.sh backend
Hello from the simple script
backend
Execute git diff HEAD^ HEAD --name-only
/usr/bin/find
[...] redacted find for ease of reading [...]
/usr/bin/git
git version 2.17.0
.gitlab-ci.yml
simplescript.sh
.gitlab-ci.yml
simplescript.sh

Results of GitLab environment info

Expand for output related to GitLab environment info
# gitlab-rake gitlab:env:info

System information System: Proxy: no Current User: git Using RVM: no Ruby Version: 2.3.6p384 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.5 Go Version: unknown

GitLab information Version: 10.6.4-ee Revision: 42f072e Directory: /opt/gitlab/embedded/service/gitlab-rails DB Adapter: postgresql DB Version: 9.6.8 URL: http://dev1.company.com HTTP Clone URL: http://dev1.company.com/some-group/some-project.git SSH Clone URL: git@dev1.company.com:some-group/some-project.git Elasticsearch: no Geo: no Using LDAP: yes Using Omniauth: no

GitLab Shell Version: 6.0.4 Repository storage paths:

  • default: /var/opt/gitlab/git-data/repositories Hooks: /opt/gitlab/embedded/service/gitlab-shell/hooks Git: /opt/gitlab/embedded/bin/git
Edited by Filip Bellander