continuous-integrationcirclecicircleci-workflows

deploy job stuck when using CircleCI to deploy dist folder over scp


My first steps with ci/cd and trying to setup CircleCI for my pet project.

I've VPS server on digitalocean and want that after build faze, content of a dist folder will be uploaded to the server via scp. My config.yml is as following:

version: 2.1

executors:
  my-executor:
    docker:
      - image: circleci/node:12.9.1-browsers
    working_directory: ~/repo

jobs:
  build:
    executor: my-executor

    steps:
      - checkout

      - restore_cache:
          keys:
            - v1-dependencies-{{ checksum "package.json" }}
            # fallback to using the latest cache if no exact match is found
            - v1-dependencies-
      - run: yarn install

      - save_cache:
          paths:
            - node_modules
            - ~/.npm
            - ~/.cache
          key: v1-dependencies-{{ checksum "package.json" }}

      - run: yarn build

  deploy:
    executor: my-executor

    steps:
      - run:
          name: Deploy Over SSH
          command: |
            scp -r dist/* $SERVER_USER_NAME@$SERVER_IP:/var/www/example.com/html

workflows:
  version: 2

  build-deploy:
    jobs:
      - build
      - deploy:
          requires:
            - build

build job flawlessly, but deploy job stuck and I see only this message:

#!/bin/bash -eo pipefail
scp -r dist/* $SERVER_USER_NAME@$SERVER_IP:/var/www/example.com/html
The authenticity of host '************ (************)' can't be established.
ECDSA key fingerprint is SHA256:Yu/i9AcPRAJtyT43QrQMdI3tSB3*************.

I've added private ssh key to circleci and public key to authorized_keys

Where I'm wrong? Thank you.


Solution

  • Ok, I was needed to add my host to known hosts manually as following to get it works:

    - run:
        name: Add to known hosts
        command: ssh-keyscan -H $SERVER_IP >> ~/.ssh/known_hosts
    

    Otherwise, it was asking if I need to add it manually and was stuck at it.