gitlabci with docker executor fails but command inside docker container works

Viewed 36

I have a gitlabci file like below. For some reason the second stage tfsec is failing with the error "wget not found"

image: ubuntu:18.04

stages:
  - wget_install
  - tfsec

wget install:
  stage: 'wget_install'
  script:
    - apt-get update
    - apt-get install -y wget

Terraform Security:
  stage: 'tfsec'
  script:
    - wget https://releases.hashicorp.com/terraform/1.0.9/terraform_1.0.9_linux_amd64.zip
    - unzip terraform_1.0.9_linux_amd64.zip
    - chmod 770 ./terraform
    - ./terraform init
    - tfsec='https://github.com/tfsec/tfsec/releases/download/v1.27.1/tfsec-linux-amd64'
    - wget $tfsec
    - chmod 777 tfsec-linux-amd64
    - pwd
    - ls
    - ./tfsec-linux-amd64 --format JUnit ./

Error in gitlab ci pipeline

$ wget https://releases.hashicorp.com/terraform/1.0.9/terraform_1.0.9_linux_amd64.zip
/bin/bash: line 124: wget: command not found 
Cleaning up project directory and file based variables     00:00  
ERROR: Job failed: exit code 1

If I try the same script for installing wget inside a docker image it works.

docker run --rm -it ubuntu:18.04 bash 
root@693265d936eb:/# apt-get install -y wget 
root@693265d936eb:/# wget wget: missing URL Usage: wget [OPTION]... [URL]...
Try `wget --help' for more options.

What am I missing in the gitlabci file?

1 Answers

You are installing wget in one job and then trying to use it in another. Each job runs in a separate container. Try moving the wget installation to the same job. In this example I have used the before_script key:

image: ubuntu:18.04

stages:
  - tfsec

Terraform Security:
  stage: 'tfsec'
  before_script:
    - apt-get update
    - apt-get install -y wget
  script:
    - wget https://releases.hashicorp.com/terraform/1.0.9/terraform_1.0.9_linux_amd64.zip
    - unzip terraform_1.0.9_linux_amd64.zip
    - chmod 770 ./terraform
    - ./terraform init
    - tfsec='https://github.com/tfsec/tfsec/releases/download/v1.27.1/tfsec-linux-amd64'
    - wget $tfsec
    - chmod 777 tfsec-linux-amd64
    - pwd
    - ls
    - ./tfsec-linux-amd64 --format JUnit ./
Related