Question

How do I configure Jenkins to build to a Droplet?

Hello,

I’m currently trying to build my projects usings Jenkins. I’ve managed to configure Jenkins to pull from my GitLab repositories but I’m struggling to figure out a way make it build on a Droplet.

Does anyone know of any simple solutions for achieving this?

Thanks, Luke


Submit an answer

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!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

When you have installed jenkins in the DO droplet, you will have an user jenkins in your system. Use that user to run a shell script to build and run the project after pulling latest code from repository.

here are the steps:

  • switch user using su jenkins
  • create ssh key using ssh-keygen -t rsa
  • copy the ssh-key from the generated public key file using cat ~/.ssh/id_rsa.pub
  • switch back to user su ,replace <DEV-SERVER-USER> with your user that belongs to your development server
  • add the key into authorized_keys appending in the nano ~/.ssh/authorized_keys In this way, the jenkins will be able to log into your droplet and do exactly the things you would do by writing manual commands.
  • add ssh key of the repository server (GitHub or Bitbucket) to the authorized_keys too.
  • add a shell script in the source code folder to do your project pulling + installing dependencies + building + running
  • make the script executable by chmod +x scriptname

there might be some issues regarding the ssh to your repository , in that case if you cannot solve it by yourself, you may try eval `ssh-agent```` and then run ssh-add ~/.ssh/id_rsa.pub``` . Hope it helps.

I have set up a Jenkins configuration that needed to build droplets on the fly. I achieved this by creating a couple scripts on the Jenkins server that I could call at build time. A more generic setup could be achieved by using doctl.

With doctl installed on your server and configured with your API keys your Jenkins instance will be able to manage droplets by running local commands.