Our Testing Implementation
Installation
We have decided to move forward with Jenkins for our CI pipeline. For this we need to host Jenkins on an AWS EC2 instance and then connect it to the DevOps Github Repository
Installing Jenkins on AWS
-
Step 1: Creating an AWS EC2 instance
Create an EC2 instance on the AWS
account. Use a free tier eligible,
Ubuntu server that comes with
pre-installed Python 3.6
One thing to keep in mind is while associating security group to this EC2 instance make sure the port 8080 is open to the world and download the secret key. - Step 2: SSH into the AWS machine Next step is to SSH into the AWS machine using the credentials downloaded in the previous step.
-
Step 3: Installing Jenkins
Follow the steps in the link to install jenkins Install Jenkins
To start the Jenkins service : "sudo service jenkins start" - Step 4: Initial Jenkins setup After following the previous steps, you need to go the url which is your public dns of your EC2 instance:8080(E.g. http://ec2-aws.compute:8080) You should be able to see the jenkins server up and running.
Here's a way of triggering a Jenkins build from a push to Github.
A reason to choose Jenkins was the availability of many plugins. One such plugin is the Github Integration Plugin
-
Step 1: Install the Github Integration Plugin
On the "Manage Jenkins" page, you will find "Manage Plugins." Then click on the "Available" tab. After checking the GitHub plugin, click on 'Download Now'. -
Step 2: Prepare Github Repository
We now need to add service to call Jenkins Github webhook on a push. Inside the github repo, go to Settings - Integrations ∧ Services - Add service
Select Jenkins(Github Integration) from drop-down menu. In the new window, enter "Jenkins Hook URL+ "/github-webhook/" e.g. http://ci.jenkins-ci.org/github-webhook/
Click on "test service" (NOTE: Services are being deprecated: new docuemntation soon on how to use webhook!) -
Step 3: Give repo access to Jenkins
User
This is a very important step. There are several ways to do so.
1. use github OAuth plugin.
2. Store plain-text user/password combo on Github
To be further discussed..
Slack integration with Jenkins
Slack is a tool used by companies on the whole and inside teams for work related communication, file sharing, notifications etc. It is important to get notified if tests fail on Jenkins hence we have integrated it with Slack to be well-informed.
- Step 1: On Jenkins page, go to Manage Plugins, click on Available tab to show all available plugins.
- Step 2: In the search bar, type 'Slack'. You will see all Slack related plugins. Select the 'Slack Notifier Plugin'.
- Step 3: Now click on 'Install without restart'. You should see 'success' written. Now you have the plugin successfully installed and ready to be configured.
- Step 4: click on Manage Plugins -- select Configure System -- scroll to the bottom of page to see section 'Global Slack Notifier Settings'. You will see that it requires a few important details to be filled in. We will get these details from Slack.
- Step 5: Add integration in Slack
First create new channel for getting Jenkins notifications. Now Go to Settings - Add an app or integration - Search for Jenkins. Click on add configurations button on the Jenkins CI page and give it rights for your newly created channel e.g. testing This will add your integration on Slack. - Step 6: Generate integration token in Slack
On sucessful integration, Slack shows a page with instructions. Scroll till Step 3 of these instructions. You will see the 'team domain' and the 'integration token' have been provided. Copy team domain value and paste it in the Jenkins page for team subdomain. - Step 7: Create Token Credential in Jenkins
Jenkins asks us to create a Token credential and not paste the token directly for security reasons. Click on add credentials - choose Jenkins - in the pop-up box, set 'Kind' as 'Secret Text' Paste the integration token in the textbox next to label 'Secret'. give an appropriate id e.g. Jenkins-integration-token and a description before you click Add. Now you can pick the recently created token from the drop-down. - Step 8: Specify channel to post notifications
Finally, type the channel name e.g. testing , in the last box. This is the channel that will get all notifications. Click on 'Test Connection', it shall result in success written so you can save this configuration by clicking on save button at the bottom. - Step 9: Set Post-build actions in Jenkins
Open the project - Click on configue (left sidebar). Scroll to the bottom till you find 'Post-build Actions' section. On clicking the button, select Slack notification. You can now select when you want to get notified e.g. when build starts/when build fails/ when it passes, etc. Save these settings. - Step 10: Trigger Build to test
Now that the configuration is ready and integration is completed you can trigger a build manually to check the notification on specified Slack channel. To do this select 'Build Now' from left side menu. Now open Slack and see the notification messages from Jenkins. Yay!