0

.gitlab-ci.yml

image: docker.x.x/vertica
cache:
    paths:
        - node_modules/

job:
    script:
        - shopt -s expand_aliases
        - alias vsql="/opt/vertica/bin/vsql"
        - source /nvm
        - nvm install 8.9
        - nvm use
        - npm install
        - npm test

Error in my node.js test:

  1) Setup
       Should create test table for tests:

      AssertionError [ERR_ASSERTION]: '/bin/sh: vsql: command not found\n' === ''
      + expected - actual

      -/bin/sh: vsql: command not found

      at Context.<anonymous> (test/index.test.js:86:20)
      at <anonymous>
      at process._tickCallback (internal/process/next_tick.js:188:7)

I looked at this answer: https://stackoverflow.com/a/37309112/1137669 but have no idea how to implement this in the gitlab-ci.yml file so that it can be accessed by the node.js script.

basickarl
  • 25,903
  • 43
  • 172
  • 270
  • 1
    Defining an alias seems completely like the wrong approach. Just add `/opt/vertica/bin` to your `PATH` instead. – tripleee Jan 31 '18 at 17:30
  • Having said that, `vsql () { /opt/vertica/bin/vsql "$@"; }` defines a function instead of an alias if you really think you need that. `export -f vsql` exports it so that it can be used by subprocesses. But again, this is not a sane solution to a completely trivial problem. – tripleee Jan 31 '18 at 17:31

1 Answers1

0

Try using a multiline script.

So:

job:
  script:
    - PATH=$$PATH:/opt/vertica/bin &&
      source /nvm &&
      nvm install 8.9 &&
      nvm use &&
      npm install &&
      npm test

Every entry in your script hash will be executed in a separate shell. See this answer on how to use multiline scripts.

marcolz
  • 2,539
  • 2
  • 21
  • 24
  • 1
    You add directories to the `PATH`, not individual binaries. – tripleee Feb 01 '18 at 17:55
  • The OP's own answer is deleted but looks to me like a better solution. Not sure why it got negative feedback; but I'm not familiar with Gitlab, so I can't tell if it actually works. (It adds a `before_script` stanza which adds the vsql directory to the `PATH` (and like this one, an unnecessary but harmless `export`)). – tripleee Feb 01 '18 at 18:00
  • @tripleee And how would the environment (which is process specific) from the before_script be passed on to the job script ? (i removed the useless eval from my answer btw.) – marcolz Feb 01 '18 at 18:01
  • Hm, probably that was the problem then. You can remove the `export` too; the `PATH` variable is exported by definition. – tripleee Feb 01 '18 at 18:13
  • @tripleee: `PATH` is exported by `default`, not by `definition`. If I unexport it, it will only affect the current shell and not its children. Try: 'unset PATH; /bin/bash -c 'export' | /bin/grep PATH` – marcolz Feb 06 '18 at 08:02
  • Technically http://pubs.opengroup.org/onlinepubs/9699919799/ allows for `PATH` to be unset or null so I guess that's basically correct. In practice, it's hard to find an environment where you are running a shell where `PATH` isn't already marked for export. – tripleee Feb 06 '18 at 08:14