Added sonarqube to gitlab ci cd config
This commit is contained in:
1 parent
034bbabecc
commit
a3db243fa2
2 files changed
+78
-35
No files matched your search
+76
-35
@@ -1,44 +1,85 @@
|
|||||||
|
# ---------------------------------------------------------
|
||||||
|
# GLOBAL SETTINGS
|
||||||
|
# ---------------------------------------------------------
|
||||||
image: oven/bun:alpine
|
image: oven/bun:alpine
|
||||||
|
|
||||||
stages:
|
stages:
|
||||||
- build
|
- build
|
||||||
- deploy
|
- test
|
||||||
|
- deploy
|
||||||
|
|
||||||
|
# Global cache used by default for Node/Bun jobs
|
||||||
cache:
|
cache:
|
||||||
key:
|
key:
|
||||||
files:
|
files:
|
||||||
- bun.lock
|
- bun.lock
|
||||||
paths:
|
paths:
|
||||||
- .next/cache/
|
- .next/cache/
|
||||||
- node_modules/
|
- node_modules/
|
||||||
|
|
||||||
|
# ---------------------------------------------------------
|
||||||
|
# STAGE 1: Build
|
||||||
|
# ---------------------------------------------------------
|
||||||
build_job:
|
build_job:
|
||||||
stage: build
|
stage: build
|
||||||
tags:
|
tags:
|
||||||
- nextjs
|
- nextjs
|
||||||
rules:
|
rules:
|
||||||
- if: $CI_COMMIT_BRANCH == "main"
|
- if: $CI_PIPELINE_SOURCE == 'merge_request_event'
|
||||||
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
|
- if: $CI_COMMIT_BRANCH == 'main'
|
||||||
script:
|
script:
|
||||||
- echo "Installing dependencies..."
|
- echo "Installing dependencies..."
|
||||||
- bun install --frozen-lockfile
|
- bun install --frozen-lockfile
|
||||||
- echo "Building the Next.js application..."
|
- echo "Building the Next.js application..."
|
||||||
- bun run build
|
- bun run build
|
||||||
artifacts:
|
artifacts:
|
||||||
paths:
|
paths:
|
||||||
- .next/
|
- .next/
|
||||||
- public/
|
- public/
|
||||||
- package.json
|
- package.json
|
||||||
expire_in: 1 week
|
expire_in: 1 week
|
||||||
|
|
||||||
|
# ---------------------------------------------------------
|
||||||
|
# STAGE 2: SonarQube Code Analysis
|
||||||
|
# ---------------------------------------------------------
|
||||||
|
sonarqube_check:
|
||||||
|
stage: test
|
||||||
|
# Override the image just for this job, including the blank entrypoint Sonar requires
|
||||||
|
image:
|
||||||
|
name: sonarsource/sonar-scanner-cli:11
|
||||||
|
entrypoint: [""]
|
||||||
|
tags:
|
||||||
|
- nextjs
|
||||||
|
variables:
|
||||||
|
SONAR_USER_HOME: "${CI_PROJECT_DIR}/.sonar" # Defines location of the analysis task cache
|
||||||
|
GIT_DEPTH: "0" # Required for accurate blame/issue assignment
|
||||||
|
# Override the global cache so Sonar can cache its own plugins separately
|
||||||
|
cache:
|
||||||
|
key: "sonar-cache-$CI_COMMIT_REF_SLUG"
|
||||||
|
paths:
|
||||||
|
- "${SONAR_USER_HOME}/cache"
|
||||||
|
- sonar-scanner/
|
||||||
|
needs: ["build_job"]
|
||||||
|
# allow_failure means if your code has "code smells", it won't stop your deployment to Portainer
|
||||||
|
allow_failure: true
|
||||||
|
rules:
|
||||||
|
- if: $CI_PIPELINE_SOURCE == 'merge_request_event'
|
||||||
|
- if: $CI_COMMIT_BRANCH == 'main'
|
||||||
|
script:
|
||||||
|
# Notice we don't need to specify the token here, the scanner automatically looks for $SONAR_TOKEN in GitLab CI/CD variables
|
||||||
|
- sonar-scanner -Dsonar.host.url="${SONAR_HOST_URL}"
|
||||||
|
|
||||||
|
# ---------------------------------------------------------
|
||||||
|
# STAGE 3: Deploy via Portainer GitOps
|
||||||
|
# ---------------------------------------------------------
|
||||||
deploy_production:
|
deploy_production:
|
||||||
stage: deploy
|
stage: deploy
|
||||||
image: curlimages/curl:latest
|
image: curlimages/curl:latest
|
||||||
tags:
|
tags:
|
||||||
- nextjs
|
- nextjs
|
||||||
rules:
|
needs: ["build_job"] # We only explicitly wait for the build to succeed to deploy
|
||||||
- if: $CI_COMMIT_BRANCH == "main"
|
rules:
|
||||||
needs: ["build_job"]
|
- if: $CI_COMMIT_BRANCH == "main"
|
||||||
script:
|
script:
|
||||||
- echo "Triggering Portainer GitOps Webhook..."
|
- echo "Triggering Portainer GitOps Webhook..."
|
||||||
- curl -X POST "https://portainer.vpn.pascalyazid.com/api/stacks/webhooks/f79fde36-37fa-43ca-a414-a6df780b0c59"
|
- curl -X POST "https://portainer.vpn.pascalyazid.com/api/stacks/webhooks/YOUR-UUID"
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
sonar.projectKey=pascalyazid_next-portfolio_b24e15c0-dd01-4711-ada0-80ff7820a766
|
||||||
|
sonar.qualitygate.wait=true
|
||||||
Reference in new issue
Block a user