Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GitLab CI with JS Linting

I have 0 experience with GitLab Continuous Integration and I need to setup a job to run ESLint on .js files.

I've already read the GitLab CI and Pipeline documentations, along with some Git Hooks, but I still have no idea how to setup this, so any detailed and starting from the very beginning answer is appreciated.

like image 360
KadoBOT Avatar asked Apr 10 '17 08:04

KadoBOT


1 Answers

First you need to setup your CI and have some runners available so they can run your continuous integration jobs. The easiest way for this is to use gitlab-ci-multi-runner (project is here along with documentation) along with the docker executor that will run your CI jobs in docker containers. Once you have configured some runners, add them to your Gitlab project so they're available to run jobs.

Once that's taken care of, you need to add a .gitlab-ci.yml file to your project. This file is used to describe the jobs that need to run during continuous integration etc. Here is an example (assuming you install eslint using npm)

image: node:latest

stages:
  - lint

eslint:
  stage: lint
  script:
    # Install ESLint in this docker container
    - npm install -g eslint
    # Configure ESLint (will read your .eslintrc file)
    - eslint --init
    # Run ESLint
    - eslint <your_js_file>

Add your .gitlab-ci.yml file, commit and push the changes. The CI pipeline should start and run the above steps.

like image 102
Jawad Avatar answered Oct 08 '22 18:10

Jawad