bash ./deploy.sh 不适用于 gitlab ci
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/49722185/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
./deploy.sh not working on gitlab ci
提问by redwolfgang20
My problem is the bash script I created got this error "/bin/sh: eval: line 88: ./deploy.sh: not found"on gitlab. Below is my sample script .gitlab-ci.yml.
我的问题是我创建的 bash 脚本在 gitlab 上出现了这个错误“/bin/sh: eval: line 88: ./deploy.sh: not found”。下面是我的示例脚本.gitlab-ci.yml。
I suspect that gitlab ci is not supporting bash script.
我怀疑 gitlab ci 不支持 bash 脚本。
image: docker:latest
variables:
IMAGE_NAME: registry.gitlab.com/$PROJECT_OWNER/$PROJECT_NAME
DOCKER_DRIVER: overlay
services:
- docker:dind
stages:
- deploy
before_script:
- docker login -u gitlab-ci-token -p $CI_BUILD_TOKEN registry.gitlab.com
- docker pull $IMAGE_NAME:$CI_BUILD_REF_NAME || true
production-deploy:
stage: deploy
only:
- master@$PROJECT_OWNER/$PROJECT_NAME
script:
- echo "$PRODUCTION_DOCKER_FILE" > Dockerfile
- docker build --cache-from $IMAGE_NAME:$CI_BUILD_REF_NAME -t $IMAGE_NAME:$CI_BUILD_REF_NAME .
- docker push $IMAGE_NAME:$CI_BUILD_REF_NAME
- echo "$PEM_FILE" > deploy.pem
- echo "$PRODUCTION_DEPLOY" > deploy.sh
- chmod 600 deploy.pem
- chmod 700 deploy.sh
- ./deploy.sh
environment:
name: production
url: https://www.example.com
And this also my deploy.sh.
这也是我的deploy.sh。
#!/bin/bash
ssh -o StrictHostKeyChecking=no -i deploy.pem ec2-user@targetIPAddress << 'ENDSSH'
// command goes here
ENDSSH
All I want is to execute deploy.shafter docker push but unfortunately got this error about /bin/bash thingy.
我想要的只是在 docker push 之后执行deploy.sh但不幸的是遇到了关于 /bin/bash thingy 的错误。
I really need your help guys. I will be thankful if you can solve my problem about gitlab ci bash script got error "/bin/sh: eval: line 88: ./deploy.sh: not found".
我真的需要你们的帮助。如果您能解决我关于 gitlab ci bash script got error "/bin/sh: eval: line 88: ./deploy.sh: not found" 的问题,我将不胜感激。
回答by Marco van Neerbos
This is probably related to the fact you are using Docker-in-Docker (docker:dind). Your deploy.sh is requesting /bin/bash as the script executor which is NOT present in that image.
这可能与您使用 Docker-in-Docker (docker:dind) 的事实有关。您的 deploy.sh 请求 /bin/bash 作为该映像中不存在的脚本执行程序。
You can test this locally on your computer with Docker:
您可以使用 Docker 在您的计算机上进行本地测试:
docker run --rm -it docker:dind bash
It will report an error. So rewrite the first line of deploy.sh to
它会报错。所以将deploy.sh的第一行改写为
#!/bin/sh
After fixing that you will run into the problem that the previous answer is addressing: ssh is not installed either. You will need to fix that too!
修复后,您将遇到上一个答案解决的问题:ssh 也未安装。你也需要解决这个问题!
回答by 1615903
docker:latest
is based on alpine linux which is very minimalistic and does not have a lot installed by default. For example, ssh
is not available out of the box, so if you want to use ssh commands you need to install it first. In your before_script
, add:
docker:latest
基于 alpine linux,它非常简约,默认情况下没有安装很多。例如,ssh
它不是开箱即用的,因此如果要使用 ssh 命令,则需要先安装它。在您的 中before_script
,添加:
- apk update && apk add openssh
回答by Mradula Ghatiya
Thanks. This worked for me by adding bash
谢谢。这通过添加bash对我有用
before_script:
- apk update && apk add bash
Let me know if that still doesn't work for you.
如果这对您仍然不起作用,请告诉我。