Below CICD code automatically triggers when we push the code into "cicd-setup" branch. Here both "build-stage" and "sonar-stage" both automatically trigger when we PUSH the code into "cicd-setup" branch every time. I don't want to trigger "sonar-stage" automatically, when we push the code. I added only: - merge_requests If i add above code, "sonar-stage" triggers only when we raise MR and other stages won't run when we raise MR and this is half solution!!.
My Question is, "sonar-stage" should not execute/trigger automatically when we PUSH the code every time. It will trigger ONLY when we raise Merge Request.
stages:
- build-stage
- sonar-stage
variables:
SONAR_HOST: "http://asdftestserver01.abc.com:9000"
SONAR_PROJECT_KEY: "test-api"
SONAR_LOGIN_TOKEN: "aaabbbbbbcccccccddddddddd"
build_stage:
stage: build-stage
only:
- cicd-setup
environment:
name: stage
script:
- echo "build stage started"
- mvn clean install
api_sonarqube_analysis:
stage: sonar-stage
only:
- merge_requests
- cicd-setup
script:
- pwd
- echo "sonarqube started"
- mvn sonar:sonar -Dsonar.projectKey=$PROJECT_KEY -Dsonar.host.url=$SONAR_HOST -Dsonar.login=$SONAR_LOGIN_TOKEN