skip to Main Content

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

2

Answers


  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
    
    Login or Signup to reply.
  2. 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
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search