Simple web server written in NodeJS using Javascript (later moved to Typescript) used as a dummy project for learning basics of CI/CD with Jenkins and SonarQube.
- Typescript v4.6.2
- Node v16.0.0
- Mocha v9.2.0
NodeJS Plugin
SonarQube Scanner for Jenkins
Add SonarQube server in global configuration
Remember to put <container_name>:<SONARQUBE_PORT> in
"Server URL", e.g. http://sonarqube:9000
Add SonarQube Scanner installation in global tools configuration, along with NodeJS installer
Jenkins file consist of several common steps for getting a better grip on how to configure project pipeline, fetch repository from SCM, create NodeJS or Docker agents and integrate Jenkins with external services like SonarQube.
Steps:
- Install dependencies
- Lint the project
- Run tests
- Analyze code using SonarQube
- Build project
SONARQUBE_USERNAME: Name of SonarQube account
SONARQUBE_PASSWORD: Password of given SonarQube user
POSTGRES_USERNAME: Name of postgres user
POSTGRES_PASSWORD: Password of given postgres user
POSTGRES_PORT: Port the Postgres will be available on
JENKINS_PORT: Port the Jenkins will be available on
SONARQUBE_PORT: Port the SonarQube will be available on
Create .env file in root directory with those variables in order to configure services inside docker-compose.yml
Verify docker-compose.yml has valid configuration:
# in the same folder as docker-compose.yml
$ docker-compose configSpin up all services using docker-compose:
# in the same folder as docker-compose.yml
$ docker-compose --env-file <path-to-env-file> up -dRemember to retrieve Jenkins' initial password from container logs or get this directly by executing command inside container. It is required in order to unlock Jenkins for the first time.
docker logs jenkins-blue-ocean # and find the password
#or
$ docker exec -it jenkins-blueocean bash "cat /var/jenkins_home/secrets/initialAdminPassword"Jenkins will be available at http://localhost:<JENKINS_PORT>
SonarQube server will be available at http://localhost:<SONARQUBE_PORT>
# Add -v flag to remove all created volumes
$ docker-compose down -v