CI SSH: Could not resolve hostname `hostname`: Temporary failure in name resolution

, ,

Hii. I’m having a CI/CD on Gitlab.com which builds a Hugo and NodeJS site and pushes it to Dreamhost via SSH.
Everything works fine until the last step when the push fails. I’m using SSH to copy the built website to Dreamhost but I get this error.

ssh: Could not resolve hostname myservername.dreamhost.com: Temporary failure in name resolution

This is the complete gitlab-ci.yml.

stages:
  - build

build:
  stage: build

  rules:
    - if: "$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH"

  image: debian:testing

  cache:
    key: $CI_COMMIT_REF_SLUG
    paths:
      - .npm/

  before_script:
    - apt update && apt install bash curl hugo openssh-client -y
    - curl -fsSL https://deb.nodesource.com/setup_19.x | bash -
    - apt update
    - apt install -y nodejs
    ## Setup NPM
    - npm ci --cache .npm --prefer-offline
    - npm install
    ## Setup SSH
    - eval $(ssh-agent -s)
    - echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add -
    - mkdir -p ~/.ssh
    - chmod 700 ~/.ssh
    - echo "$SSH_KNOWN_HOSTS" >> ~/.ssh/known_hosts
    - chmod 644 ~/.ssh/known_hosts

  script:
    - echo "Building site…"
    - npm run build
    - echo "Creating an archive of public…"
    - tar -czf public.tar.gz public
    - echo "Cleaning the old site from server…"
    ## Error comes for the below line
    - ssh "$SERVER_LOCATION" "cd mywebsite.org && rm -rf *"
    - echo "Copying archive to server…"
    - sftp -C -b utils/batch.txt "$SERVER_LOCATION"
    - echo "Extracting and deleting the archive from server…"
    - ssh "$SERVER_LOCATION" "tar -xzf public.tar.gz -C mywebsite.org --strip-components=1 && rm public.tar.gz"
    - echo "Done"

I’m really confused how to resolve this as other domain names are properly resolved (like nodesource.com) but only this one fails. Also I’m able to SSH the host from my laptop. So what could be issue here?

Thanks for reading.