skip to Main Content

I have a Azure Devops Build Pipeline running on a Ubuntu Hosted Agent which requires "unzip" to be installed.

When running the pipeline, I am getting this error which suggests unzip is not installed, which seems to go against the documentation.

unzip: command not found

Anyway, I have tried to install unzip using apt-get, but get an error about permissions.

apt-get install -y unzip
Could not open lock file /var/lib/dpkg/lock-frontend - open (13: Permission denied)

I then tried again using sudo apt-get, but then I get an error about sudo not being installed.

sudo apt-get install -y unzip
sudo: command not found

So how do I install a package such as unzip (or sudo) as part of the Pipeline Build?

Here is an example:

jobs:
- job: Test
  pool:
    vmImage: 'ubuntu-20.04'
  steps:
  - checkout: none 
  - download: current
  - task: CmdLine@2
    inputs:
      script: 'sudo apt-get update'
    displayName: Update APT

Here is the result:

Starting: Update APT
Generating script.
Script contents:
sudo apt-get update
/bin/bash --noprofile --norc /__w/_temp/a7297a55-95b9-46e2-985d-260e57d915ac.sh
/__w/_temp/a7297a55-95b9-46e2-985d-260e57d915ac.sh: line 1: sudo: command not found
##[error]Bash exited with code '127'.
Finishing: Update APT

Does anyone have a working example of using sudo in a build pipeline?

UPDATE
This has been a little bit of a red herring. This seems to only happen when using a container. When the container is removed from the pipeline, sudo and unzip exist. I have since replaced the container with a Docker CLI install and Bash scripts to do it manually.

2

Answers


  1. The script section allows executing the commands. You can include the command to install unzip in script task and that should install the dependencies. Below code should work for apt package manager.

    - script: |
        sudo apt-get install -y unzip
      displayName: 'Install dependencies'
    

    Ref: https://learn.microsoft.com/en-us/azure/devops/pipelines/ecosystems/python?view=azure-devops

    Login or Signup to reply.
  2. Azure DevOps pipelines often run in isolated containers where you may not have administrative privileges to use sudo or install packages.Use the built-in unzip command

        - script: |
        unzip your_file.zip
      displayName: 'Unzip File'
    

    updated version for above

    steps:
    - script: 'unzip $(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip'
      displayName: 'Command Line Script'
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search