chmod: ‘og=’ 之后缺少操作数Gitlab CI/CD 执行器=shell

发布于 2025-01-20 19:31:58 字数 1607 浏览 0 评论 0原文

对于开发服务器的管道:

   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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

青瓷清茶倾城歌 2025-01-27 19:31:58

终于找到了导致问题的原因。正如数字海洋指南中所述,我已将变量设置为仅可由受保护分支访问,但忘记使 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文