How do I add the gitlab ci content into existing pipelines

Hello, I am trying to integrate an existing gitlab repo to sonarqube. However, that repo is using a custom image we built and for some reason I couldn’t add the additional sonarqube .gitlab-ci.yml content to it.

kipping Git submodules setup
Restoring cache
00:01
Checking cache for scan...
FATAL: file does not exist                         
Failed to extract cache
Executing "step_script" stage of the job script
00:00
$ bootstrap ${CI_RUNNER_SKELETON_KEY_BASE64_TOKEN} ${CI_RUNNER_SKELETON_KEY_ACCOUNT_NAME}
/scripts-5028-2330605/step_script: line 177: bootstrap: command not found
Cleaning up project directory and file based variables

This is some of the error message. Can someone help me with this?

What is the full content of your gitlab-ci.yml file?

This is the existing .gitlab-ci.yml. It has its own image.

image: gcr.io/t/terraform:
services:
- docker:18-dind

variables:
  DOCKER_DRIVER: 
  DOCKER_HOST: 
  PROJECT: 
  REGION: 
  CLUSTER: 
  NAMESPACE: 
  DOCKER_TLS_CERTDIR: 
  TF_PLUGIN_DIR: 
  TF_GET_PLUGINS: 
  FF_USE_LEGACY_KUBERNETES_EXECUTION_STRATEGY: 0

stages:
  - test
  - plan
  - manual-apply
  - manual-destroy

before_script:
  - bootstrap ${CI_RUNNER_SKELETON_KEY_BASE64_TOKEN} ${CI_RUNNER_SKELETON_KEY_ACCOUNT_NAME}
  - terraform-robot $PROJECT $REGION $CLUSTER $NAMESPACE
  - export GOOGLE_APPLICATION_CREDENTIALS=$HOME/.gcloud/terraform_robot_credentials.json

lint:
  stage: test
  script:
    - make init && make test

plan:
  stage: plan
  script:
    - make init && make ci-plan
  artifacts:
    paths:
    - tfplan
    expire_in: 1 month

apply:
  stage: manual-apply
  dependencies:
    - plan
  script:
    - make init && make ci-apply
  when: manual
  only:
    refs:
      - main
  
destroy:
  stage: manual-destroy
  script:
    - make init && make ci-destroy
  allow_failure: true
  dependencies:
    - plan
  when: manual
  only:
    refs:
      - main

And how does it look when you try and add the additional SonarQube content?

image: gcr.io/t/terraform:
services:
- docker:18-dind

variables:
  DOCKER_DRIVER: 
  DOCKER_HOST: 
  PROJECT: 
  REGION: 
  CLUSTER: 
  NAMESPACE: 
  DOCKER_TLS_CERTDIR: 
  TF_PLUGIN_DIR: 
  TF_GET_PLUGINS: 
  FF_USE_LEGACY_KUBERNETES_EXECUTION_STRATEGY: 
  SONAR_USER_HOME: "${CI_PROJECT_DIR}/.sonar"
  GIT_DEPTH: "0"

stages:
  - scan
  - test
  - plan
  - manual-apply
  - manual-destroy

before_script:
  - bootstrap ${CI_RUNNER_SKELETON_KEY_BASE64_TOKEN} ${CI_RUNNER_SKELETON_KEY_ACCOUNT_NAME}
  - terraform-robot $PROJECT $REGION $CLUSTER $NAMESPACE
  - export GOOGLE_APPLICATION_CREDENTIALS=

scan:
  stage: scan
  image: 
    name: sonarsource/sonar-scanner-cli:latest
    entrypoint: [""]
  cache:
    key: "${CI_JOB_NAME}"
    paths:
      - .sonar/cache
  script: 
    - sonar-scanner -Dsonar.projectKey=security_italpha_drawio_AYLQdxtpP_KkG93sb6Ht -Dsonar.qualitygate.wait=true
  allow_failure: true
  only:
    - merge_requests
    - master # or the name of your main branch
    - develop

lint:
  stage: test
  script:
    - make init && make test

plan:
  stage: plan
  script:
    - make init && make ci-plan
  artifacts:
    paths:
    - tfplan
    expire_in: 1 month

apply:
  stage: manual-apply
  dependencies:
    - plan
  script:
    - make init && make ci-apply
  when: manual
  only:
    refs:
      - main
  
destroy:
  stage: manual-destroy
  script:
    - make init && make ci-destroy
  allow_failure: true
  dependencies:
    - plan
  when: manual
  only:
    refs:
      - main

@Colin the error message seems to suggest that the cache file cannot be found. This doesn’t make sense because I’ve included the variables already.

Thanks for the help. This question can be closed now. It turned out that the existing .gitlab-ci.yml file contains a before_script block and the sonar scan job doesn’t support it. So overriding the before_script block in sonar scan job resolved the issue.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.