0

i am trying to make a autodeploy with github, i execute this js to have a "server" to receive the hook from github, that work amazing, but i need then to execute a script to download the repository, but this code don't execute my hook.sh. I don't have experience with node earlier, so, i am lost here.

// Listen on port 9001
var gith = require('gith').create( 9001 );
// Import execFile, to run our bash script
var execFile = require('child_process').execFile;

gith({
    repo: 'username/autodeploy'
}).on( 'all', function( payload ) {
    if( payload.branch === 'master' )
    {
            // Exec a shell script
            execFile('/root/nodeapp/hook.sh', function(error, stdout, stderr) {
                    // Log success in some manner
                    console.log( 'exec complete' );
            });
    }
});

ok, i was testing this manually and seems that the problem is with gith({.... all that is inside this doesn't work, anyone have an idea?

thanks to everyone

xploshioOn
  • 4,035
  • 2
  • 28
  • 37
  • Does your `execFile()` callback get called? If so, what does `error.code`, `stdout`, and `stderr` say? Is `/root/nodeapp/hook.sh` set as executable and it starts with the appropriate hashbang? – mscdex Jul 27 '14 at 06:16
  • i don't know how to read the errors, github send a petition to the script and the script responds, but i don't know how to see if one error ocurr... yes, the hook.sh is a executable script and have the necesary, i execute this directly and do what have to do. the problem is with this script. thanks – xploshioOn Jul 27 '14 at 06:25
  • just create a new temporary js file and put there your `execFile` code, run the file and see if the code works. It is easier to debug program by pieces, not as a whole. – alandarev Jul 27 '14 at 06:31
  • ok, so a file with this? var execFile = require('child_process').execFile; execFile('/root/nodeapp/hook.sh', function(error, stdout, stderr) { // Log success in some manner console.log( 'exec complete' ); }); and then how i execute that? – xploshioOn Jul 27 '14 at 06:33
  • ok, i test it, and work, do what this have to do. so the problem is with the payload i think, thanks mscdex and alandarev. can you see a error with gith? – xploshioOn Jul 27 '14 at 06:38
  • done guys, I answer my question bellow, thanks. – xploshioOn Jul 27 '14 at 07:26

1 Answers1

1

well, the problem was with

gith({
    repo: 'username/autodeploy'
}).on( 'all', function( payload ) {....

i changed that for

gith({
    repo: 'username/autodeploy'
}).on( 'file:all', function( payload ) {....

and that solved my problem. thanks @mscdex and @alandarev for tell me to test.

xploshioOn
  • 4,035
  • 2
  • 28
  • 37