5

I am attempting to use a shared runner to run a script which handles env vars necessary for deployment. The section of my YAML config that is failing is:

release:
  stage: release
  image: docker:latest
  only:
    - master
  services:
    - docker:dind
  variables:
    DOCKER_DRIVER: overlay
  before_script:
    - docker version
    - docker info
    - docker login -u ${CI_REGISTRY_USER} -p ${CI_BUILD_TOKEN} ${CI_REGISTRY}
  script:
    - dckstart=$(cat dockerfile-start)
    - export > custom_vars
    - chmod +x scripts/format-variables.sh
    - bash scripts/format-variables.sh
    - dckenv=$(cat custom_vars)
    - dckfin=$(cat dockerfile-finish)
    - echo -e "$dckstart\n$dckenv\n$dckfin" >> Dockerfile
    - rm dockerfile-start dockerfile-finish custom_vars
    - docker build -t ${CI_REGISTRY}/${CI_PROJECT_PATH}:latest --pull .
    - docker push ${CI_REGISTRY}/${CI_PROJECT_PATH}:latest
  after_script:
    - docker logout ${CI_REGISTRY}

This step fails & gives the error:

$ chmod +x scripts/format-variables.sh
$ bash scripts/format-variables.sh
/bin/sh: eval: line 101: bash: not found

I have attempted:

  • /bin/bash scripts/format-variables.sh

    /bin/sh: eval: line 114: /bin/bash: not found

  • cd scripts && ./format-variables.sh

    /bin/sh: eval: line 116: ./format-variables.sh: not found

  • --shell /bin/bash scripts/format-variables.sh

    /bin/sh: eval: line 114: --shell: not found

The final attempt was an idea I grabbed from the docs. I have not specified the shared runners to use but I assume the one being used is UNIX based as all other UNIX commands work.

Is it possible to do this via a shared runner or do I need to get a dedicated runner for this?

NOTE: I have to use Bash for this script & not Shell due to using arrays. If I were to use Shell, I would come up with the error mentioned here

wmash
  • 4,032
  • 3
  • 31
  • 69
  • there's no bash in that image, you need to install it. see https://stackoverflow.com/questions/40944479/how-to-use-bash-with-an-alpine-based-docker-image/40944512 – Iron Bishop Feb 08 '20 at 09:03
  • 1
    Thanks for the suggestion @IronBishop, I went with this fix in the end. Put an answer & I will accept – wmash Feb 10 '20 at 16:46

2 Answers2

8

The docker:latest image doesn't contain bash, to save space. You can either install it (see How to use bash with an Alpine based docker image?) or use a different base image (like CentOS or Ubuntu).

Iron Bishop
  • 1,749
  • 1
  • 7
  • 16
2

Use an image that has bash installed like CentOS or Ubuntu.

Ghonima
  • 2,978
  • 2
  • 14
  • 23