When using a shell-runner it possible to pass if statements on a remote server?

Here is such a test gitlab-ci.yml:

 world_branch: variables: dir: "/home/TATATA" environment: staging script: - ssh-keyscan -H 192.168.0.12 >> ~/.ssh/known_hosts - ssh root@192.168.0.12 " 'if [[ -d "$dir" ]]; then rm -r $dir && mkdir $dir fi' " - rsync -avz --delete-after --exclude=".git" --exclude=".gitlab-ci.yml" . root@192.168.0.12:/home/TATATA only: - world 

After starting the task, here is the error:

 bash: if [[ -d /home/TATATA ]] rm -r /home/TATATA && mkdir /home/TATATA fi: No such file or directory 

    1 answer 1

    It was solved only in this way:

     - ssh root@192.168.0.12 " if [[ -d "$dir" ]]; then rm -r $dir && mkdir $dir; fi " 

    That is, you need to put the commands after the shell;

    For constructions where shell commands are two or more, you just need to add to the end of each again;

    For example:

     - ssh root@192.168.0.12 " if [[ ! -d "$dir" ]]; then mkdir $dir; mkdir $dir/test; fi "