​In my last blog post, Get the Most out of the GitLab Template in Skytap Cloud, we put together a new configuration that had a simple development machine along with the GitLab template for doing source control. This time we are going to expand that template to include doing automatic builds via Jenkins whenever someone pushes code to GitLab (think of it as Continuous Integration in the cloud).

Note: If you didn’t go through that blog post with me or keep the configuration, you can go back and review it first, since we will be expanding on it in this one.

First off, you need to spin up the configuration we set up last time. From there, let’s add in the Jenkins template:

  1. Click Add VMs
  2. In the search box enter ‘Jenkins’
  3. Select the Jenkins template and click Add
  4. Start the Jenkins template

You can use SmartClient to connect to the Jenkins VM. But first, we need to quickly install Git. Log in to the Jenkins VM as root and run the following command to install Git for Jenkins CI to use:

You also need to generate an SSH key so Jenkins can log in to GitLab. Run the following and just hit enter for any questions asked by ssh-keygen. Answer ‘yes’ to the scp command (don’t worry if you get an error, we just need to save the GitLab server’s ssh key). After running the cat command, copy the output (you’ll need to paste that into GitLab later):

Log out of the Jenkins VM and connect to your client VM. Both GitLab and Jenkins are built on Ubuntu 12.04.1 LTS Server, so neither of them has a web browser. You’ll be using the client machine for almost everything, but if you prefer, you could map HTTP Port 80 on both GitLab and Jenkins to Skytap published services and connect to them that way through your browser. However, if you do this, when we tie GitLab and Jenkins together, use the URLs I provide and not the published service ones.

Now it’s time to allow your Jenkins server to log in to GitLab. You can re-use your skytap@local.host account for this (though you could create separate accounts for the two). Launch Firefox (Applications > Internet > Firefox web browser). In the address bar, go to: http://host-1, then:

  1. Login as skytap@local.host
  • Username: skytap@local.host
  • Password: skytap
  • Click the box on the upper right-hand side of the page
  • Click the SSH Keys tab
  • Click Add new
  • Set title to ‘Jenkins’
  • For Key, copy in the full output of the cat command above (will start with ssh-rsa and end with skytap@local.host)
  • Click Save
  • Now you can configure Jenkins. In the Firefox address bar, type: http://host-2 to get to Jenkins. Configure Jenkins CI so that it can connect to your GitLab instance and pull code from it:

    1. Click the Manage Jenkins link
    2. Click the Manage Plugins link
    3. Click the Available tab
    4. Type ‘git’ in the filter box
    5. Check the Gitlab Hook Plugin box
    6. Click the Download now and install after restart button
    • Jenkins will install the Git Plugin, ruby-runtime, and Gitlab Hook Plugin
    • Check the Restart Jenkins when installation is complete box
    • Wait for Jenkins to restart
  • Click Manage Plugins on the left
  • Click the Installed tab
    • You should see ruby-runtime plugin, the Jenkins Git plugin, and the Gitlab Hook Plugin:
  • Click Manage Jenkins on the left
  • Click Configure System
  • Scroll down to ‘Git’ and click the Git Installations button
    • You should see that Git is installed and all ready to go
  • Scroll down to ‘Git Plugin’ and set the following:
    • Global Config User.Name = skytap
    • Global Config User.Email = skytap@local.host
  • Click Save
  • You are now ready to create your first job in Jenkins. Since Node.js doesn’t require any actual building, this project will check out the entire source tree from GitLab. (In my next post, we’ll actually do something with it while it is checked out.)

    1. Click New Job in Jenkins
    2. Enter ‘express_sample’ (or whatever you want) for ‘Job Name’
    3. For this example, use “Build a free-style software project” for the project type (again, feel free to change this to fit your needs)
    4. Click OK
    5. Scroll down to ‘Source Code Management’ and Select Git
    • Repository URL: git@host-1:express_sample.git
    • Branches to build: master
  • Scroll down to ‘Build Triggers’
  • Check the Poll SCM option (don’t enter a schedule)
  • Click Save
  • Jenkins should be good to go. You can run a manual build and see that Jenkins can check out the express_sample source code from GitLab. The last step is telling GitLab to trigger Jenkins for you when a check-in occurs. In the Firefox address bar, go back to GitLab (http://host-1), then:

    1. Log in as skytap@local.host
    2. Choose the express_sample project
    3. Click the Hooks lower tab
    4. In the url field, enter: http://host-2/git/notifyCommit?url=git@host-1:express_sample.git
    5. Click Add Web Hook

    Now let’s test everything out. Open a terminal window on the client machine again and follow along (you’ll make a small change to your Node.js application to check-in).

    Go over to Jenkins in Firefox after you push the changes to GitLab (git push origin master). You should see that Jenkins ran another build successfully.

    Just like with GitLab, all three of these VMs are in the same configuration to make life easier. You could also move a combination of these parts to different configurations and tie them together with ICNR or VPN back to your internal network.

    As always, if you have any questions, don’t hesitate to get in touch with Skytap Support or your Skytap representative. Also, you may want to keep this configuration around a bit longer. We’ll be using it again in my next blog post where we’ll make Jenkins do something cool with our Node.js application after it’s checked out of GitLab.

    Until next time,

    Matt

    Facebooktwittergoogle_pluslinkedinFacebooktwittergoogle_pluslinkedin
    rssrss