chmod: ‘og=’ 之后缺少操作数Gitlab CI/CD 执行器=shell
对于开发服务器的管道:
stages:
- deploy
deploy to dev:
stage: deploy
tags:
- development
script:
- chmod og= $ID_RSA_DEVELOPMENT
- apk update && apk add openssh-client
- ssh -i $ID_RSA_DEVELOPMENT -o StrictHostKeyChecking=no $SERVER_USER@$SERVER_IP_DEVELOPMENT "cd /home/deployer/folder-name && bash dev.sh"
environment:
name: development
url: http://{IP Address}
only:
- dev
该管道是通过推动开发分支触发的。生产渠道似乎在相同的代码中运行良好,其中%开发%替换为%生产%和 - 开发的生产。但是,当使用Dev Branch运行管道时,管道中显示了以下错误:
$ chmod og= $ID_RSA_DEVELOPMENT
chmod: missing operand after ‘og=’
Try 'chmod --help' for more information.
有人可以帮助我解决这个问题,因为我几乎没有选择自己的选择。 谢谢欢呼!
[编辑] 这是在其他项目中使用的完整YML文件
stages:
- deploy
deploy to master:
stage: deploy
tags:
- production
script:
- chmod og= $ID_RSA_PRODUCTION
- apk update && apk add openssh-client
- ssh -i $ID_RSA_PRODUCTION -o StrictHostKeyChecking=no $SERVER_USER@$SERVER_IP_PRODUCTION "cd /home/project-folder/ && bash prod.sh"
environment:
name: production
url: https://1.2.3.4/
only:
- master
deploy to dev:
stage: deploy
tags:
- development
script:
- chmod og= $ID_RSA_DEVELOPMENT
- apk update && apk add openssh-client
- ssh -i $ID_RSA_DEVELOPMENT -o StrictHostKeyChecking=no $SERVER_USER@$SERVER_IP_DEVELOPMENT "cd /home/project-folder/ && bash dev.sh"
environment:
name: development
url: https://1.2.3.4/
only:
- dev
I have the following in .gitlab-ci.yml for pipeline for development server:
stages:
- deploy
deploy to dev:
stage: deploy
tags:
- development
script:
- chmod og= $ID_RSA_DEVELOPMENT
- apk update && apk add openssh-client
- ssh -i $ID_RSA_DEVELOPMENT -o StrictHostKeyChecking=no $SERVER_USER@$SERVER_IP_DEVELOPMENT "cd /home/deployer/folder-name && bash dev.sh"
environment:
name: development
url: http://{IP Address}
only:
- dev
This pipeline is triggered by pushing to dev branch. The pipeline for production seems to working fine with the same code with %DEVELOPMENT% replaced with %PRODUCTION% and - dev with - production. But when running the pipeline with dev branch the following error is shown in pipeline:
$ chmod og= $ID_RSA_DEVELOPMENT
chmod: missing operand after ‘og=’
Try 'chmod --help' for more information.
Can someone help me figure this out because I am almost out of options here figuring this out on my own.
Thanks Cheers!!
[EDITED]
Here is the complete yml file that is working in other project
stages:
- deploy
deploy to master:
stage: deploy
tags:
- production
script:
- chmod og= $ID_RSA_PRODUCTION
- apk update && apk add openssh-client
- ssh -i $ID_RSA_PRODUCTION -o StrictHostKeyChecking=no $SERVER_USER@$SERVER_IP_PRODUCTION "cd /home/project-folder/ && bash prod.sh"
environment:
name: production
url: https://1.2.3.4/
only:
- master
deploy to dev:
stage: deploy
tags:
- development
script:
- chmod og= $ID_RSA_DEVELOPMENT
- apk update && apk add openssh-client
- ssh -i $ID_RSA_DEVELOPMENT -o StrictHostKeyChecking=no $SERVER_USER@$SERVER_IP_DEVELOPMENT "cd /home/project-folder/ && bash dev.sh"
environment:
name: development
url: https://1.2.3.4/
only:
- dev
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
终于找到了导致问题的原因。正如数字海洋指南中所述,我已将变量设置为仅可由受保护分支访问,但忘记使 dev 分支受保护。这就是为什么 og="${ID_RSA_DEVELOPMENT}" 没有返回任何内容,因为 dev 没有受到保护并且正在尝试访问受保护分支的文件。
将 dev 分支更改为受保护,并且管道开始工作,因为它现在能够访问 ID_RSA_DEVELOPMENT 变量的内容。
感谢大家的帮助,非常感谢。
Finally found out what was causing the issue. As stated in the digital ocean guide I had set the variable to be accessible by protected branch only but had forgot to make dev branch protected. That is why og="${ID_RSA_DEVELOPMENT}" was returning nothing as dev was not protected and was trying to access file for protected branch.
Changed the dev branch to be protected and poof the pipeline started working as it was now able to access contents of ID_RSA_DEVELOPMENT variable.
Thanks for your help everyone, much appreciated.