Issue
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
Solution
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.
Answered By - Always Baked Answer Checked By - Timothy Miller (WPSolving Admin)