4

In my bitbucket-pipelines.yml file, I have this:

  - step:
      image: python:3.7.2-stretch
      name: upload to s3
      script:
        - export S3_BUCKET="elasticbeanstalk-us-east-1-133233433288"
        - export VERSION_LABEL=$(cat VERSION_LABEL)
        - sudo apt-get install -y zip # required for packaging up the application
        - pip install boto3==1.3.0 # required for upload_to_s3.py
        - zip --exclude=*.git* -r /tmp/artifact.zip . # package up the application for deployment
        - python upload_to_s3.py # run the deployment script

But when I run this pipeline in Bitbucket, I get an error, which the output:

+ sudo apt-get install -y zip
bash: sudo: command not found

Why would it not know what sudo means? Isn't this common to all Linux machines?

CodyBugstein
  • 21,984
  • 61
  • 207
  • 363

2 Answers2

1

The "command not found" error is printed in stderr when it does not find the binary in the folders configured in env $PATH

first you need to found out if it exists with :

find /usr/bin -name "sudo"

if you find the binary try to set the PATH variable with :

export PATH=$PATH:/usr/bin/ 

then try to run sudo again.

  • I can't easily run this command though as I have to first put it in my bitbucket-pipelines.yml file and then commit it. Anyways I guess all this would do would confirm that it's not found. My question is why not – CodyBugstein Mar 27 '19 at 06:22
  • it seems that your session profile you are using does not have some environment variables configured, try to execute "echo $PATH" and see if you have configured the binary path /usr/bin on it. – Miguel Ángel Retamozo Sanchez Mar 27 '19 at 06:25
-1

No, sudo is not available everywhere.

But you don’t have to bother with it, anyway. When running the image, you are root, so you can simply run apt-get without spending a thought on permissions.

BlueM
  • 3,658
  • 21
  • 34
  • But when I did it without sudo, I got an error telling me I didn't have permission to some directories – CodyBugstein Mar 27 '19 at 06:22
  • Which directories could you not access? Were they part of your cloned repository or other directories in the image? – phod Mar 27 '19 at 12:09
  • @CodyBugstein: Whatever problem you have – I’m pretty sure the problem is not related to `apt-get`. Run `docker run -it python:3.7.2-stretch /bin/bash`, then `apt-get update && apt-get install -y zip` and it will work. – BlueM Mar 27 '19 at 18:52