Run local mock/test server in parallel to my product's build

Hello everyone!

I have a iOS mobile app that is build and tested via GitLab CI pipeline. I’d like to use mock server that is run locally for testing purposes.

How do tell GitLab CI that I’d like to start some local server, then start the build & test of my app and stop the local server when entire pipeline for my app is finished?

I thought that it may be done using some before_script like this:

before_script:
    - ./server &

But it’s seems to be flaky and I’m not sure if CI will stop/kill this background command properly.

The other approach would be to create another job in parallel, like sample configuration bellow. However I’m still not sure if all processes will be finished gracefully and if it’s correct flow in first place.

Any help?

stages:
  - testing
  - deploy

mock_server:
  stage: testing
  script:
     - ./server
unit_and_ui_tests:
  dependencies: []
  stage: testing
  artifacts:
    paths:
      - test_logs/test_report.xml
    reports:
      junit: test_logs/test_report.xml
  script:
    - fastlane scan
  tags:
    - ios