5 - CI-CD pipeline for Node.js Application

Repository: https://gitlab.com/nanuchi/mynodeapp-cicd-project

2 - Run Unit Tests & Collect Test Reports

Important

Test report is a useful thing to use in my current work.

It starts at 3:20 in the video

In the app used as an example, the tests generate a junit.xml file that can be parsed by GitLab and show as a report in the web interface.

To show the report generated by the jest-junit in the gitlab we need to add this to our .gitlab-ci.yml:

# ...

run_unit_tests:
  # ...
  artifacts:
    when: always
    reports:
      junit: app/junit.xml

Another useful thing about these reports in the GitLab's UI is in the Merge Requests page. It shows the tests that failed.

Notes

Issues I faced when implementing this at my work:

  • For eslint jobs I needed to use formatters --format junit
  • For different jobs, I needed to create differente artifacts:reports (e.g.: junit-eslint-start-e2e.xml)
  • In a report I got an error from gitlab when it tried to parse the .xml file (like this one described here), and it made me give up from using this kind of report ☹️

3 - Build Docker Image & Push to Private Registry

I've learned that gitlab.com provides a private registry for your docker image.

I also noticed that the self-hosted GitLab doesn't have this option (at least not by default).

4 - GitLab Environments: Describe where code is deployed

Important

This is also cool to have in my work.

# ...
deploy_to_dev:
  # ...
  environment:
    name: development
    url: http://dev.server.com:3000
Question

Does docker-compose automatically replace references to ${VARIABLES} in the file's contents with the value of the respective environment variables?