1

I have installed SonarQube on a ubuntu machine via a docker image. All working fine and I'm able to log in without issues.

Have connected to our GitLab installation and see all available projects, when I try to configure the existing pipeline with the following, I got stuck.

I have the following pipeline.yml in use (partially shown here):

sonarqube-check:
  stage: sonarqube-check
  image: mcr.microsoft.com/dotnet/core/sdk:latest
  variables:
    SONAR_USER_HOME: "${CI_PROJECT_DIR}/.sonar"  # Defines the location of the analysis task cache
    GIT_DEPTH: "0"  # Tells git to fetch all the branches of the project, required by the analysis task
  cache:
    key: "${CI_JOB_NAME}"
    paths:
      - .sonar/cache
  script: 
      - "apt-get update"
      - "apt-get install --yes openjdk-11-jre"
      - "dotnet tool install --global dotnet-sonarscanner"
      - "export PATH=\"$PATH:$HOME/.dotnet/tools\""
      - "dotnet sonarscanner begin /k:\"my_project_location_AYDMUbUQodVNV6NM7qxd\" /d:sonar.login=\"$SONAR_TOKEN\" /d:\"sonar.host.url=$SONAR_HOST_URL\" "
      - "dotnet build"
      - "dotnet sonarscanner end /d:sonar.login=\"$SONAR_TOKEN\""
  allow_failure: true
  only:
    - master

All looking good, but when it runs it gives me this error:

$ apt-get update
bash: apt-get: command not found

I just don't know how to fix this and can't find a solution on the internet somewhere

Maxime
  • 452
  • 4
  • 9
Mario
  • 582
  • 5
  • 18
  • The `apt-get: command not found` message means that the image doesn't contain the Aptitude package manager. What OS is this image based on? – Richard May 17 '22 at 16:52
  • the gitlab runner is on ubuntu 20.04 – Mario May 18 '22 at 11:22
  • Right, but the image being used for the sonarqube-check job is 'mcr.microsoft.com/dotnet/core/sdk:latest' – Richard May 18 '22 at 13:14
  • added sudo to all commands and now it fires, but how can I make sure to let it function without sudo command? – Mario May 19 '22 at 06:23
  • That's due to the way the Docker image is set up. Since these commands are being run in a CI container that will eventually be disposed of, I wouldn't worry about factoring out calls to 'sudo'. – Richard May 19 '22 at 15:28

2 Answers2

1

dotnet/core/sdk image has apt (not apt-get):

$ docker run -ti --rm mcr.microsoft.com/dotnet/core/sdk:latest sh
# apt update

Following SonarCube documentation, you can use their docker image with the CLI already installed:

image:
  name: sonarsource/sonar-scanner-cli:latest
variables:
  SONAR_TOKEN: "your-sonarqube-token"
  SONAR_HOST_URL: "http://your-sonarqube-instance.org"
  SONAR_USER_HOME: "${CI_PROJECT_DIR}/.sonar" # Defines the location of the analysis task cache
  GIT_DEPTH: 0 # Tells git to fetch all the branches of the project, required by the analysis task
cache:
  key: ${CI_JOB_NAME}
  paths:
    - .sonar/cache
sonarqube-check:
  stage: test
  script:
    - sonar-scanner -Dsonar.qualitygate.wait=true
  allow_failure: true
  only:
    - master
Maxime
  • 452
  • 4
  • 9
0

Apt /apt-get command not found - Problem fixed:

I think in your /usr/bin have no the apt and apt-get, you can download it and install it on that https://packages.debian.org/stretch/apt, like this

wget http://ftp.cn.debian.org/debian/pool/main/a/apt/apt_1.4.9_amd64.deb
dpkg -i apt_1.4.9_amd64.deb
jokereven
  • 19
  • 4