Configure Jenkins to run on AWS(EC2) & setup GitHub web hook for Android apps
I am going to explain how to setup a web hook to trigger a build on Jenkins whenever a change pushed to Github, I have amazon EC2 server already running,
After launching a EC2 , connect to your instance using anyone of below method
- A standalone SSH client
- Session Manager
- EC2 Instance Connect (browser-based SSH connection)
For this example I am connecting using third way that is browser-based SSH connection,
Once you successfully connect, can see command line interface(CLI), like
Now it is time to install Jenkins, but that need to install Java first
execute below line to install java
[ec2-user@ip-172–31–28–91 ~]$ sudo yum install java-1.8.0
To download and install Jenkins follow below:
- To ensure that your software packages are up to date on your instance, use the following command to perform a quick software update:
[ec2-user@ip-172–31–28–91 ~]$ sudo yum update –y
2. Add the Jenkins repo using the following command:
[ec2-user@ip-172–31–28–91 ~]$ sudo wget -O /etc/yum.repos.d/jenkins.repo http://pkg.jenkins- ci.org/redhat/jenkins.repo
3. Import a key file from Jenkins-CI to enable installation from the package:
[ec2-user@ip-172–31–28–91 ~]$ sudo rpm — import https://pkg.jenkins.io/redhat/jenkins.io.key
4. Install Jenkins:
[ec2-user@ip-172–31–28–91 ~]$ sudo yum install jenkins -y
5. Start Jenkins as a service:
[ec2-user@ip-172–31–28–91 ~]$ sudo service jenkins start
Jenkins is now installed and running on your EC2 instance. To configure Jenkins go to browser and connect to http://<your_server_public_DNS>:8080, you can get your EC2 Public DNS from AWS console,
You will be able to access Jenkins through its management interface:
Now to get administrator password, simply go to Command line interface and navigate to give file path and run cat command , you able to see password, enter it and go to next page,
[ec2-user@ip-172–31–28–91 ~]$ sudo cat /var/lib/jenkins/secrets/initialAdminPassword
The Jenkins installation script directs you to the Customize Jenkins page. Click Install suggested plugins.Once the installation is complete, enter Administrator Credentials, click Save Credentials, and then click Start Using Jenkins, you may asked to create new user, if required create and go to Jenkins Dashboard.
Now create a Freestyle project go to New Item -> Enter name -> Select Freestyle Project
Go to source control management and Select Git
enter Repository URl, and click apply and save. if you getting any error about Git , please make sure git is install on EC2, check it by entering below line on Command line interface
[ec2-user@ip-172–31–28–91 ~]$ git — version
if not installed, try below line to install,
[ec2-user@ip-172–31–28–91 ~]$ sudo yum install git-all
once done, check the installation directory to configure in Jenkins
[ec2-user@ip-172–31–28–91 ~]$ whereis git
In Git section of Global Tool Configuration enter the correct path to Git executable,
Once git setup done, Select Github hook trigger for GITScm Polling in Build Triggers section in Source code management section
Now select Use Gradle Wrapper in build section to run Gradle for your android project and click on Apply and Save this configuration.
once done everything correctly, you can see this on Dashboard,
hopefully you able to build by clicking on Item name and selecting Build Now option, if it’s working, in final step will configure WebHook to initial a build once we push any changes to Github.
before going to setup webHook, you need to authenticate Jenkins to access gitHub, for that Enter Github user name/password on Credential section of Dashboard
Go to Github repo setting and add new webHook
Payload url will be your Jenkins url ending with “/github-webhook/”
select “just Event when you want to trigger”, thats It, New webHook is ready to trigger, once you click on add Webhook, it will test it with a delivery, you can see delivery result, if response is 200
Hope this will give a guide to configure a Github webHook for android app on Jenkins CI/CD, if any question please feel free to comment here.