hi mate, so i have some question, can someone please help me
so my goals is i want to run a job when someone push / commit to some directory in main branch, a test job and scan job, i have 4 jobs and i already test them and only working 2 jobs only, when i tried to run the other job, it says that " ‘scan’ job need ‘test’ job, but ‘test’ jobs is not in any previous stage ", i confused because my 2 others job working fine,
here’s the example of my repo directory
- root
- apps
- service1
- service2
- service3
- service4
- apps
so i just want to run job only if some changes in my service directory, and here’s my gitlab-ci
image: docker:23.0.1-dind-alpine3.17
services:
- docker:23.0.1-dind
variables:
WORK_DIR: 'dirpath'
stages:
- test
- build
- deploy
##### JOB
.review: &review
- echo "PROJECT_NAME=${PROJECT_NAME}" >> var.env
- echo "PROJECT_NAME_U=${PROJECT_NAME_U}" >> var.env
- rm -f Dockerfile
- cp tools/docker/unit-test/${PROJECT_NAME}/Dockerfile Dockerfile
- docker build -t ${CI_REGISTRY_IMAGE}/${PROJECT_NAME}:staging .
- docker cp $(docker create --name tc ${CI_REGISTRY_IMAGE}/${PROJECT_NAME}:staging):${WORK_DIR}/coverage/apps/${PROJECT_NAME}/lcov.info . && docker rm tc
.scan: &scan
- sonar-scanner -X
-Dsonar.host.url="${SONAR_URL}"
-Dsonar.login="${SONAR_TOKEN}"
-Dsonar.sources="${SONAR_SERVICE}"
-Dsonar.tests="${SONAR_TEST}"
-Dsonar.projectKey="${SONAR_PROJECTKEY}"
##### UNIT TEST & SCAN #####
sonarscan:
stage: test
image: sonarsource/sonar-scanner-cli
variables:
SONAR_TOKEN: "${SONAR_TOKEN}"
SONAR_HOST_URL: "${SONAR_URL}"
SONAR_URL: "${SONAR_URL}"
SONAR_USER_HOME: "${CI_PROJECT_DIR}/.sonar"
SONAR_SERVICE: "apps/${PROJECT_NAME}/src"
SONAR_TEST: "apps/${PROJECT_NAME}/test"
SONAR_PROJECTKEY: "CASCADE_${PROJECT_NAME_U}"
GIT_DEPTH: 0
script: *scan
allow_failure: true
only:
refs:
- main
needs:
job: unit-test
artifacts: true
unit-test:
stage: test
script: *review
allow_failure: true
variables:
PROJECT_NAME: "api"
PROJECT_NAME_U: "API"
only:
refs:
- main
changes:
- apps/api/**/*
artifacts:
reports:
dotenv: var.env
paths:
- lcov.info
expire_in: 1 hour
unit-test:
stage: test
script: *review
allow_failure: true
variables:
PROJECT_NAME: "notification"
PROJECT_NAME_U: "NOTIFICATION"
only:
refs:
- main
changes:
- apps/notification/**/*
artifacts:
reports:
dotenv: var.env
paths:
- lcov.info
expire_in: 1 hour
unit-test:
stage: test
script: *review
allow_failure: true
variables:
PROJECT_NAME: "audience"
PROJECT_NAME_U: "AUDIENCE"
only:
refs:
- main
changes:
- apps/audience/**/*
artifacts:
reports:
dotenv: var.env
paths:
- lcov.info
expire_in: 1 hour
unit-test:
stage: test
script: *review
allow_failure: true
variables:
PROJECT_NAME: "data-process"
PROJECT_NAME_U: "DATA-PROCESS"
only:
refs:
- main
changes:
- apps/data-process/**/*
artifacts:
reports:
dotenv: var.env
paths:
- lcov.info
expire_in: 1 hour
so i didnt know why pipeline only running when i change to service 1 and service2 ( api and notification ) service, but didnt running on service 3 and 4 ( data-process and audience ) even tho the code is same ?
and i need some help about this configuration, so letsay i change to service2 and job working fine. but i want to running job in parallel letsay, i made changes to service 1 and service2, commit and push at the same time, with this config, only 1 job is running. can i make more than1 job running parallel if i changes more than 1 service ?
thanks