Jaydeep Patel
Jaydeep Patel

Reputation: 156

PM2 : post-deploy hook failed

I'm using PM2 deploy script to deploy code to my FreeBSD server.

Step 1: pm2 deploy production setup.
Successfully execute setup command. pre-setup script is also working.

Step 2: pm2 deploy production.
It gives post-deploy hook failed error. However, pre-deploy-local command is working.

--> Deploying to production environment
--> on host ****
○ deploying origin/master
○ executing pre-deploy-local
This is a local executed command
○ hook pre-deploy
○ fast forward master
Your branch is up to date with 'origin/master'.
Already on 'master'
From git.***/*
* branch master -> FETCH_HEAD
Already up to date.
○ executing post-deploy npm install && pm2 start

Ambiguous output redirect.
post-deploy hook failed
Deploy failed

Moreover, If I run pm2 deploy production exec "npm install && pm2 start" from my local machine then it works fine.

PM2 ecosystem.config.js

apps: [{
    name: 'Myapp',
    script: 'app.js',
    env: {
        NODE_ENV: 'development'
    },
    env_production: {
        NODE_ENV: 'production'
    }
}],

deploy: {
    production: {
        user: 'user',
        host: 'myhost',
        ref: 'origin/master',
        repo: 'git@***/**',
        path: 'Some/Path',
        'ssh_options': ["ForwardAgent=yes","StrictHostKeyChecking=no"],
        "pre-setup" : "pkg install git && npm install -g pm2@latest",
        "pre-deploy-local" : "echo 'This is a local executed command'",
        "post-deploy" : "npm install && pm2 start",

    }
}

Upvotes: 2

Views: 3047

Answers (1)

johndpope
johndpope

Reputation: 5249

It looks like you are missing an extra step to perhaps build the files?

post-deploy" : "npm install && npm run build && pm2 start"

Upvotes: 1

Related Questions