Search code examples
rubydockerpipelinebitbucket-pipelinesapt-get

bash: apt-get: command not found in bitbucket pipeline


I've been trying to build a pipeline to test my deploys in bitbucket but i keep getting this problem

+ apt-get update && \ apt-get install -y \ fonts-liberation \ libasound2 \ libatk-bridge2.0-0 \ libatk1.0-0 \ libatspi2.0-0 \ libcups2 \ libdbus-1-3 \ libdrm2 \ libgbm1 \ libgtk-3-0 \ libnspr4 \ libnss3 \ libu2f-udev \ libvulkan1 \ libxcomposite1 \ libxdamage1 \ libxfixes3 \ libxkbcommon0 \ libxrandr2 \ xdg-utils && \ rm -rf /var/lib/apt/lists/*
Get:1 http://deb.debian.org/debian bullseye InRelease [116 kB]
Get:2 http://security.debian.org/debian-security bullseye-security InRelease [48.4 kB]
Get:3 http://deb.debian.org/debian bullseye-updates InRelease [44.1 kB]
Get:4 http://security.debian.org/debian-security bullseye-security/main amd64 Packages [271 kB]
Get:5 http://deb.debian.org/debian bullseye/main amd64 Packages [8068 kB]
Get:6 http://deb.debian.org/debian bullseye-updates/main amd64 Packages [18.8 kB]
Fetched 8565 kB in 1s (6690 kB/s)
Reading package lists...
bash:  apt-get: command not found

Doing some research the problem could be in the image im using, but using the same image in a docker works perfect so i don't really see where's the issue

Here's my yml file

image: ruby:3.0.3

pipelines:
  default:
    - step:
        name: Run minitests
        script:
          # Dependencies          
          - apt-get update && \
            apt-get install -y \
                fonts-liberation \
                libasound2 \
                libatk-bridge2.0-0 \
                libatk1.0-0 \
                libatspi2.0-0 \
                libcups2 \
                libdbus-1-3 \
                libdrm2 \
                libgbm1 \
                libgtk-3-0 \
                libnspr4 \
                libnss3 \
                libu2f-udev \
                libvulkan1 \
                libxcomposite1 \
                libxdamage1 \
                libxfixes3 \
                libxkbcommon0 \
                libxrandr2 \
                xdg-utils && \
              rm -rf /var/lib/apt/lists/*
          # Configure chrome and chromedriver          
          - dpkg -i driver/117.0.5938.132/google-chrome.deb
          - export CHROMEDRIVER_PATH=driver/117.0.5938.132/
          - export PATH="${CHROMEDRIVER_PATH}:${PATH}"
          - export BROWSER=:chrome
          - export LOAD=eager
          - gem install bundler
          - bundle install
          - rake runner:run_tests

Any help is welcome

I tried using sudo and it's practically the same problem, also tried using another packet manager and got the same result


Solution

  • You can get rid of the backslashes at the end of your script lines.

    Backslashes are used for declaring multilines commands directly interpreted by Bash.

    But here in YAML what you see is NOT what you get. Multilines are transposed into a single one and backslashes are interpreted as regular characters when they should be escape characters. For example the following YAML:

    script:
        - apt-get update \
        && apt-get install foo
    

    Will have this JSON output:

    {
      "script": [
        "apt-get update \\ && apt-get install foo"
      ]
    }