0

I have a situation where one of the script deploys the application on to a local host, but does not have any exit code after which my tests needs to run to access the application. Below is my yaml -

    test-e2e-mac:
  stage: test
  cache:
    <<: *global_cache
    policy: pull
  tags:
    - mac-p
  script:
    - yarn install && yarn build && yarn workspace sandbox dev
    - yarn run test:e2e

The command yarn workspace sandbox dev deploys the application to local host but does not have any exit code, so the job gets stuck there instead of proceeding to the next script which is yarn run test:e2e.

Below is the log output -

$ yarn install && yarn build && yarn workspace sandbox dev
➤ YN0000: ┌ Resolution step
Resolution step
00:00
➤ YN0000: └ Completed
➤ YN0000: ┌ Fetch step
Fetch step
00:01
➤ YN0000: └ Completed in 1s 96ms
➤ YN0000: ┌ Link step
Link step
00:15
➤ YN0000: └ Completed in 15s 241ms
➤ YN0000: Done with warnings in 16s 724ms
➤ YN0000: [build:*css] yarn run build:css exited with code 0
➤ YN0000: [build:*js] yarn run build:js exited with code 0
➤ YN0000: warn  - No build cache found. Please configure build caching for faster rebuilds. Read more: https://nextjs.org/docs/messages/no-cache
➤ YN0000: Attention: Next.js now collects completely anonymous telemetry regarding usage.
➤ YN0000: This information is used to shape Next.js' roadmap and prioritize features.
➤ YN0000: You can learn more, including how to opt-out if you'd not like to participate in this anonymous program, by visiting the following URL:
➤ YN0000: https://nextjs.org/telemetry
➤ YN0000: 
➤ YN0000: info  - Checking validity of types...
➤ YN0000: info  - Creating an optimized production build...
➤ YN0000: info  - Compiled successfully
➤ YN0000: info  - Collecting page data...
➤ YN0000: info  - Generating static pages (0/3)
➤ YN0000: info  - Generating static pages (3/3)
➤ YN0000: info  - Finalizing page optimization...
➤ YN0000: 
➤ YN0000: Page                                       Size     First Load JS
➤ YN0000: ┌ ○ /                                      14.2 kB        85.6 kB
➤ YN0000: ├   └ css/01242c01debb6154.css             1.06 kB
➤ YN0000: ├   /_app                                  0 B            71.5 kB
➤ YN0000: └ ○ /404                                   193 B          71.6 kB
➤ YN0000: + First Load JS shared by all              71.5 kB
➤ YN0000:   ├ chunks/framework-c4190dd27fdc6a34.js   42 kB
➤ YN0000:   ├ chunks/main-bb9def7d8910e0b5.js        28.1 kB
➤ YN0000:   ├ chunks/pages/_app-0a7fb017d9a7d5bb.js  507 B
➤ YN0000:   ├ chunks/webpack-5023c8273a18d257.js     780 B
➤ YN0000:   └ css/653c6652631f0700.css               876 B
➤ YN0000: 
➤ YN0000: ○  (Static)  automatically rendered as static HTML (uses no initial props)
➤ YN0000: 
➤ YN0000: info  - using build directory: /Users/ppami/builds/i2gVvArX/0/dolby-io-sdk/spider-man/apps/sandbox/.next
➤ YN0000: info  - Copying "static build" directory
➤ YN0000: info  - No "exportPathMap" found in "/Users/ppami/builds/i2gVvArX/0/dolby-io-sdk/spider-man/apps/sandbox/next.config.js". Generating map from "./pages"
➤ YN0000: info  - Launching 9 workers
➤ YN0000: info  - Exporting (0/2)
➤ YN0000: info  - Copying "public" directory
➤ YN0000: info  - Exporting (2/2)
➤ YN0000: Export successful. Files written to /Users/ppami/builds/i2gVvArX/0/dolby-io-sdk/spider-man/apps/sandbox/out
➤ YN0000: error - ESLint: Failed to load plugin 'testcafe' declared in '../../.eslintrc.js': Cannot find module 'eslint-plugin-testcafe' Require stack: - /Users/ppami/builds/i2gVvArX/0/dolby-io-sdk/spider-man/__placeholder__.js Referenced from: /Users/ppami/builds/i2gVvArX/0/dolby-io-sdk/spider-man/.eslintrc.js
➤ YN0000: Done in 13s 678ms
ready - started server on 0.0.0.0:3000, url: http://localhost:3000
event - compiled successfully in 1362 ms (175 modules)
ERROR: Job failed: execution took longer than 1h0m0s seconds

The job failed because it timed out. My application was deployed to http://localhost:3000

Any pointers here??

sytech
  • 29,298
  • 3
  • 45
  • 86
pawanamigo
  • 35
  • 3

1 Answers1

0

Just like on your local system, running the server will block forever. You can't enter any more command in your terminal until the server stops.

To get around this in GitLab CI, you can background the server task to allow the rest of the script to continue. In bash, to background a command, end the command with an &.

  script:
    - yarn install && yarn build 
    - yarn workspace sandbox dev &   # start server in the background
    - sleep 5 # give it a few seconds to start up!
    - yarn run test:e2e
sytech
  • 29,298
  • 3
  • 45
  • 86
  • Thanks that worked. But now it seems that job still times-out as the server is live..any idea on how do we handle its closure?? – pawanamigo May 13 '22 at 01:31
  • Hmm. I wouldn't have expected that to be the case, but maybe [this answer](https://stackoverflow.com/a/1911387/5747944) will help you. Or maybe just try `exit 0` – sytech May 13 '22 at 03:48