I am using the gitlab pipeline for unit testing, building, pushing, and deploying the below pipeline script.
image: node:18.13.0
default:
tags:
- $RUNNER_TAG
variables:
DOCKER_TLS_CERTDIR: ''
API_PATH: '$CI_PROJECT_DIR/apps/api'
WEB_PATH: '$CI_PROJECT_DIR/apps/web'
FF_USE_FASTZIP: 'true'
# These can be specified per job or per pipeline
ARTIFACT_COMPRESSION_LEVEL: 'fast'
CACHE_COMPRESSION_LEVEL: 'fast'
stages:
- pre-check
- quality
- build
- push
- deploy
validate_branch_name:
stage: pre-check
script:
- echo $CI_COMMIT_REF_NAME | grep -Eq '^feature/|^bugfix/|^release/' || (echo "Invalid branch name"; exit 1)
rules:
- if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
when: always
- if: '$CI_COMMIT_BRANCH != $CI_DEFAULT_BRANCH'
when: always
validate_commit_message:
stage: pre-check
script:
- |
if ! git log -1 --pretty=%B | grep -Eq '^(feat|fix|chore|docs|style|refactor|test|perf): .+'; then
echo "Invalid commit message format"
exit 1
fi
rules:
- if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
when: always
unit_test:
image: node:18.13.0
stage: test
needs:
- validate_branch_name
- validate_commit_message
script:
- npm run test:web
artifacts:
paths:
- $CI_PROJECT_DIR/coverage/
reports:
coverage_report:
coverage_format: cobertura
path: $CI_PROJECT_DIR/coverage/**/**/cobertura-coverage.xml
allow-failure: true
only:
- develop
retry:
max: 1
when: always
# check the code quality using sonar-scanner
sonarqube_check:
image:
name: sonarsource/sonar-scanner-cli:latest
entrypoint: ['']
stage: push
variables:
SONAR_USER_HOME: '${CI_PROJECT_DIR}/.sonar'
GIT_DEPTH: '0'
cache:
key: '${CI_JOB_NAME}'
paths:
- .sonar/cache
before_script:
- export VERSION=$(node -p "require('./package.json').version")
script:
- sonar-scanner -Dsonar.projectVersion=$VERSION
allow_failure: true
only:
- develop
needs:
- job: unit_test
artifacts: true
# install node modules
.distributed:
interruptible: true
before_script:
- npm install --location=global npm-cli-login
- npm ci --cache .npm --prefer-offline
cache:
key:
files:
- package-lock.json
paths:
- .npm/
- node_modules
policy: pull-push
retry:
max: 2
when: always
# push the images to the gitlab container registry for the serverfull deployment
.push_serverfull:
image: docker:20.10.16
stage: push
cache: {}
services:
- docker:20.10.16-dind
script:
- docker login $REGISTRY -u $REGISTRY_USER -p $REGISTRY_PASSWORD
artifacts:
reports:
dotenv: build.env
expire_in: 60 min
# dev environment
build_dev:
image: node:18.13.0
stage: build
extends: .distributed
script:
- export NODE_OPTIONS="--max-old-space-size=8192"
- npx semantic-release
- npx nx affected --target=build --all --parallel=3 --configuration=dev
artifacts:
paths:
- $CI_PROJECT_DIR/dist/
expire_in: 60 min
only:
- develop
environment:
name: dev
push_dev:
extends: .push_serverfull
only:
- develop
environment:
name: dev
needs:
- job: build_dev
artifacts: true
When click on update we can’t run this pipeline because error coming with below message. How can solve this?
**Unable to create pipeline**
'unit_test' job needs '**validate_branch_name**' job, but '**validate_branch_name**' is not in any previous stage
'unit_test' job needs '**validate_commit_message**' job, but '**validate_commit_message**' is not in any previous stage
Without adding the above mentioned “validate_commit_message” and “validate_branch_name” pipeline is running perfectly only this error message comes with adding these jobs to pipeline.