# Starter pipeline
# Start with a minimal pipeline that you can customize to build and deploy your code.
# Add steps that build, run tests, deploy, and more:
# https://aka.ms/yaml

trigger:
- dev
 
pool:
  vmImage: 'ubuntu-latest'
 
jobs:
- job: SSHJob
  displayName: 'Run SSH command on remote server'
  steps:
  - task: UseNode@1
    inputs:
      versionSpec: '19.7.0'  # Specify the Node.js version here
      checkLatest: true

  - script: |
      sudo npm install -g npm@latest
      node -v
      npm -v
    displayName: 'Verify Node.js and npm versions'

  - task: SSH@0
    inputs:
      sshEndpoint: 'Nucleus-SSH'
      runOptions: 'commands'
      commands: |
        echo "Checking SSH connectivity"
        whoami
        node -v
        npm -v
        echo "before path"
        cd /var/www/backend/graviti-mir-api.lexyslabs.com
        echo "after path"
        node -v
        pwd
        echo "git checking"
        sudo git -C /var/www/backend/graviti-mir-api.lexyslabs.com remote set-url origin https://dev.azure.com/lexystech/Project%20Nucleus/_git/Project-Nucleus-BE
        echo "git Seocnd checking"
        sudo git -C /var/www/backend/graviti-mir-api.lexyslabs.com pull https://4pnv6ffmikfcwvjdgvw4udrczde7qeel3kbbrtzdyew3ql4chngq:@dev.azure.com/lexystech/Project%20Nucleus/_git/Project-Nucleus-BE dev 2>/dev/null
        echo "git check"
        sudo npm install --prefix /var/www/backend/graviti-mir-api.lexyslabs.com --loglevel=error
        echo "installed"
        sudo pm2 stop server
        sudo pm2 restart server
        sudo echo "This is a new file created from Azure Pipeline" > newfile.txt
        uptime
      failOnStdErr: true


