Issue
I am implementing Auto Build in my Gitlab project. For that I am using .gitlab-ci.yml
file with multi-line YAML blocks containing shell commands, the code is as follows:
if [ "${GITLAB_USER_LOGIN}" != "nadirabbas" ]
then
echo "Building"
if [ ! -d "dist" ]; then mkdir dist; fi
if [ ! -f "dist/index.html" ]; then touch dist/index.html; fi
fi
I have tried many solutions such as putting a ;
after the if statement, also after the fi
keyword, but nothing seems to work, My job log returns the following syntax error:
syntax error near unexpected token `fi'
I have tried to google it, but other solutions don't seem to work. The shell my runner is using is bash
.
Solution
As I noted in the comments, the easiest approach would probably to have the script in its own file (make sure it's executable!), and then just call it from gitlab ci.
E.g., you can have a build.sh
file:
#!/bin/bash
if [ "${GITLAB_USER_LOGIN}" != "nadirabbas" ]
then
echo "Building"
if [ ! -d "dist" ]; then mkdir dist; fi
if [ ! -f "dist/index.html" ]; then touch dist/index.html; fi
fi
And then call it from the yml:
some_task:
image: ubuntu:18.04
script:
- ./build.sh
Answered By - Mureinik Answer Checked By - Marilyn (WPSolving Volunteer)