Hi,
I have a rails server running in my Ubuntu 14.04 instance and I host my code in github.com. For user’s pushing to github, I have setup a webhook to my app which listens to any POST call from github and tries to execute a ruby script gitscript.rb when the POST has all correct payloads.
Unfortunaltely the script doesn’t do a git pull and I am stumped to run this perfectly. Any help would be appreciated.
Below is my code to listen to webhooks and it runs the script, but the commands in the script don’t run, I have all the permission required for the ruby script.
def webhooks
push = JSON.parse(request.body.read)
if some_condition_that_should_be_true
logger.info "Yes go ahead and pull"
logger.info "Ran the git pull command" if `cd /home/server && git pull >> cat.txt`
logger.info "Ran the ruby" if `ruby /home/server/gitscript.rb`
logger.info "Last command"
else
logger.info push
end
render :json => { :code => 'Webhooks came good' }, :status => 200
end
And my ruby script is below and yes it has all permissions correct, for test sake I made them 777
#!/bin/env ruby
`cd /home/server && git pull`
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Have you tried running the script manually to see if there are any errors?
One thing I notice is that, at least on Ubuntu, the shebang line is wrong.
/bin/env: bad interpreter: No such file or directory
You want to use:
#!/usr/bin/env ruby
Also, make sure you are pulling from GitHub using the https url and not the git@ one. You can check this by running:
git remote show origin
If the fetch url looks like:
Fetch URL: git@github.com:username/project.git
It might be failing as it is will try to connect over SSH. If that’s what you want to do, you’ll need to create an SSH key on the server without a password so that the script doesn’t block waiting for you to enter it. You’ll also need to add the public key to your GitHub account.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.