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?


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.

2 answers

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.

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 authorizedkeys appending in the “`nano ~/.ssh/authorizedkeys”` 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-agentand then runssh-add ~/.ssh/id_rsa.pub` .
Hope it helps.

Submit an Answer