gitlab CI/CD how to execute a multiline command as shown

Viewed 1190

I want to execute a command like below in the gitlabl CI/CD

ssh $DEPLOY_USER@$DEPLOY_HOST <<'ENDSSH'                                                                    
set -x -o verbose;
execute some command here
set +x
ENDSSH

How to add such commands in script

deploy-to-stage:
  stage: deploy
  before_script:
    - "which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )"
    - eval $(ssh-agent -s)
    - echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add - > /dev/null
    - mkdir -p ~/.ssh
    - chmod 700 ~/.ssh
    - echo "$SSH_KNOWN_HOSTS" > ~/.ssh/known_hosts
    - chmod 644 ~/.ssh/known_hosts
    - docker login -u gitlab-ci-token -p $CI_JOB_TOKEN registry.gitlab.com
  script:
    -   *** HERE I WANT TO RUN THAT COMMAND ***

How can i do that

1 Answers

you can do it like that:

script:
  - |
    ssh $DEPLOY_USER@$DEPLOY_HOST <<'ENDSSH'                                                                    
    set -x -o verbose;
    execute some command here
    set +x
    ENDSSH
Related