Bash脚本GitLab共享运行器

时间:2020-02-08 00:38:29

标签: bash gitlab gitlab-ci gitlab-ci-runner

我正在尝试使用共享运行程序来运行脚本,该脚本处理部署所需的env var。我的YAML配置失败的部分是:

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}

此步骤失败并给出错误:

$ chmod + x scripts / format-variables.sh
$ bash脚本/format-variables.sh
/ bin / sh:评估:第101行:bash:找不到

我尝试过:

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

    / bin / sh:评估:第114行:/ bin / bash:找不到

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

    / bin / sh:评估:第116行:./format-variables.sh:找不到

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

    / bin / sh:评估:第114行:--shell:找不到

最后一次尝试是我从the docs那里得到的一个想法。我没有指定要使用的共享运行程序,但我假设正在使用的共享运行程序是基于UNIX的,因为所有其他UNIX命令都可以工作。

是否可以通过共享跑步者来做到这一点?或者我需要为此指定专门的跑步者吗?

注意由于使用数组,我必须为此脚本使用Bash而不是Shell。如果要使用Shell,我会提出here

2 个答案:

答案 0 :(得分:2)

docker:latest图像不包含bash,以节省空间。您可以安装它(请参阅How to use bash with an Alpine based docker image?)或使用其他基础映像(例如CentOS或Ubuntu)。

答案 1 :(得分:0)

使用安装了bash的图像,例如CentOSUbuntu