Automate deploying .jar file to server via gitlab ci

102 views Asked by At
stages:
  - deploy

deploy:
  stage: deploy
  script:
    - apt-get update && apt-get install -y sshpass
    - sshpass -P $SSH_PASSWORD ssh -p $SSH_PORT -o StrictHostKeyChecking=no $SSH_USER@$SSH_SERVER "mkdir -p $DEPLOY_DIR"
    - scp -P $SSH_PORT -o StrictHostKeyChecking=no target/your-java-app.jar $SSH_USER@$SSH_SERVER:$DEPLOY_DIR
    - sshpass -P $SSH_PASSWORD ssh -p $SSH_PORT -o StrictHostKeyChecking=no $SSH_USER@$SSH_SERVER "cd $DEPLOY_DIR && java -jar your-java-app.jar"
  only:
    - master # Change this to your desired branch

Here is my .gitlab-ci.yml file. It can not find the sshpass.Error:

$ sshpass -P $SSH_PASSWORD ssh -p $SSH_PORT -o StrictHostKeyChecking=no $SSH_USER@$SSH_SERVER "mkdir -p $DEPLOY_DIR"
SSHPASS: Failed to run command: No such file or directory
Cleaning up project directory and file based variables
ERROR: Job failed: exit code 1

I have shown full path. But it gave below error:

$ /usr/bin/sshpass -P $SSH_PASSWORD ssh -p $SSH_PORT -o StrictHostKeyChecking=no $SSH_USER@$SSH_SERVER "mkdir -p $DEPLOY_DIR"
SSHPASS: Failed to run command: No such file or directory
Cleaning up project directory and file based variables
ERROR: Job failed: exit code 1

I expected it deploys jar file to the server.

0

There are 0 answers