title: Gitlab CI/CD Deployment to Local Tomcat
body: <p>I am new to CI/CD and now trying to deploy a maven Java project in Gitlab repository using the Gitlab CI/CD features. The deployment step will be successful if it is destined to the build-in docker image. But, when I am trying to deploy in my local computer destination, the deployment step fails. Could anybody have any idea about this?</p>
  
  <p>I have tried in Mac OSX to register and run the gitlab-runner to process the CI/CD. I have already installed the docker.</p>
  
  <p>This is the .gitlab-ci.yml file.</p>
  
  <pre><code>image: maven:latest
  
  stages:
    - build
    - test
    - deploy
  
  variables:
    MAVEN_CLI_OPTS: "-s .m2/settings.xml --batch-mode"
    MAVEN_OPTS: "-Dmaven.repo.local=.m2/repository"
    SSH_PRIVATE_KEY: "b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAA..."
    SSH_KNOWN_HOSTS: "# YmkSun.local:22 SSH-2.0-OpenSSH_7.9
  ymksun.local ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDSMOpRI..."
    DEPLOY_USER: "yemyokyaw"
    DEPLOY_HOST: "YmkSun.local"
    DEPLOY_PATH: "/Users/yemyokyaw/Documents/tmp"
  
  
  cache:
    paths:
      - .m2/repository/
      - target/ 
  
  build_app:
    stage: build
    dependencies: []
    script:
    - mvn $MAVEN_CLI_OPTS compile
  
  test:
    stage: test
    script:
      - mvn $MAVEN_CLI_OPTS test
  
  deploy:stand:
    stage: deploy
    dependencies: []
    environment:
      name: staging
    before_script:
      - 'which ssh-agent || ( apt-get update -y &amp;&amp; apt-get install openssh-client -y )'
      - eval $(ssh-agent -s)
      - echo "$SSH_PRIVATE_KEY" | tr -d '\r' 
      - mkdir -p ~/.ssh
      - chmod 700 ~/.ssh
      - echo "$SSH_KNOWN_HOSTS" &gt; ~/.ssh/known_hosts
      - chmod 644 ~/.ssh/known_hosts
    script:
  
      - ssh yemyokyaw@YmkSun.local "cd /builds/ymksun/sample-cicd-parent &amp;&amp; git checkout master &amp;&amp; git pull origin master &amp;&amp; exit"
  
      - ssh $DEPLOY_USER@$DEPLOY_HOST "cd '$DEPLOY_PATH'; git pull; docker restart home-assistant"
  </code></pre>
  
  <p>Error message when I try the second script:</p>
  
  <blockquote>
    <p>$ ssh $DEPLOY_USER@$DEPLOY_HOST "cd '$DEPLOY_PATH'; git pull; docker
    restart home-assistant" ssh: connect to host localhost port 22: Cannot
    assign requested address</p>
  </blockquote>
  
  <p>Error message when I try the first script:</p>
  
  <blockquote>
    <p>$ ssh yemyokyaw@YmkSun.local "cd
    /builds/ymksun/sample-cicd-parent &amp;&amp; git checkout master &amp;&amp; git pull
    origin master &amp;&amp; exit" Host key verification failed.</p>
  </blockquote>