Skip to content

Instantly share code, notes, and snippets.

@hemantshekhawat
Last active October 6, 2017 10:03
Show Gist options
  • Save hemantshekhawat/d5eeba380de5b820083b8adba409fa64 to your computer and use it in GitHub Desktop.
Save hemantshekhawat/d5eeba380de5b820083b8adba409fa64 to your computer and use it in GitHub Desktop.
How to setup Gitlab CI for AngularJs App

setup Gitlab Runner on server (ubuntu):

  1. Add GitLab's official repository via apt-get or yum: Debian/Ubuntu: curl -L https://packages.gitlab.com/install/repositories/runner/gitlab-ci-multi-runner/script.deb.sh | sudo bash RHEL/CentOS: curl -L https://packages.gitlab.com/install/repositories/runner/gitlab-ci-multi-runner/script.rpm.sh | sudo bash
  2. sudo apt-get update
  3. sudo apt-get install gitlab-ci-multi-runner

register gitlab runner

  1. sudo gitlab-ci-multi-runner register
    • enter CI url from https://gitlab.com/xxx/project/runners
    • enter token
    • enter runner description
    • enter executor (shell) That's it, runner is started automatically. Now you need to configure .gitlab-ci.yml

For .gitlab-ci.yml linting and validating use:

https://gitlab.com/ci/lint

.gitlab-ci.yml NodeJS/AngularJS apps example:

cache:
  paths:
   - node_modules/

# install FE npm dependencies and build app
fe_build:
  stage: build
  only:
   - master
  script:
   - cd /opt/bitnami/apps/wott-new/htdocs/wottAPI/client
   - sudo npm install
   - sudo gulp build

# install BE npm dependencies
be_dependencies:
  stage: build
  only:
   - master
  script:
   - cd /opt/bitnami/apps/wott-new/htdocs/wottAPI/server
   - sudo npm install

# install EXPORTER npm dependencies
exporter_dependencies:
  stage: build
  only:
   - master
  script:
   - cd /opt/bitnami/apps/wott-new/htdocs/wottAPI/exporter
   - sudo npm install

# reload API
server_reload:
  stage: reload
  only:
   - master
  script:
   - cd /opt/bitnami/apps/wott-new/htdocs/wottAPI
   - sudo pm2 reload all

# stages (runs in series)
stages:
  - build
  - reload

To make sure gitlab CI can run shell commands:

Grant sudo permissions to the gitlab-runner user as this is who is executing the build script.

sudo usermod -a -G sudo gitlab-runner

You need to edit your sudoers file. On your machine type sudo visudo and add the following line:

username ALL = NOPASSWD: /bin/git

This will allow username to use git without any password.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment