Sunday, October 22, 2017

How to configure webhooks in Bitbucket to trigger a build in Jenkins? How to trigger automated builds in Jenkins through Bitbucket?

Jenkins jobs can be triggered many ways. Here are those ways:

1. pull - using poll scm
2. Webhooks (push mechanism) - by triggering a build from Bitbucket or GitHub for every repository changes.
3. through slack channel. Click here to learn about trigger Jenkins job using Slack.

Webhooks are triggers that enables developers to trigger Jenkins jobs automatically every time there is a code change.

we will see in this article how to trigger a(push) build for every change in bitbucket repository:

Changes needed in Jenkins

1. Click on Manage Jenkins.   
2. Click on Configure Global Security. 
3. Uncheck the option for Prevent Cross Site Request Forgery exploits
4. In matrix-based security change: 

for Anonymous user, do the below:

Overall - Read   
Job - Build  
Job - Read   

Job - Workspace



 
 
 
 
Select the job you would like to configure webhook is for. Choose configure Also you need to have token created for the job you would like to trigger. Click on the build job. Go to triggers section and click on Trigger builds remotely (e.g., from scripts)

 Authentication Token field. 
Also uncheck poll SCM option(if it was selected earlier) 















Changes in Bitbucket

1. go to bitbucket, choose the repository, go to settings, click on web hooks.



2. enter title, url which is your jenkins job url - append build/?token=myToken
 example the url should be like this - http://jenkins_public_dns_server_url:8080/job/myFirstAutomateJob/build?token=myToken

Sample url is given below:

http://jenkins_url:8080/job/myFirstAutomateJob/build?token=myToken

For e.g.,
jenkins public dns name - jenkins_url:8080
Freestyle job name -  myFirstAutomateJob
token= myToken
3. status should be active
4. click on skip certificate verification
5. triggers --> repository push

Now make a code change in bitbucket to see if that triggers a build in Jenkins automatically.

Monday, October 16, 2017

Tomcat 8 hung on Ubuntu 16.0.4


Apply the below fix when you have tomcat not starting issues:
Actually, by setting the following in /etc/default/tomcat8, I was fine:
JAVA_OPTS="-Djava.security.egd=file:/dev/./urandom -Djava.awt.headless=true -Xmx1024m -XX:MaxPermSize=512m -XX:+UseConcMarkSweepGC"

Sunday, October 15, 2017

sonar-maven-plugin:2.6:sonar: java.lang.UnsupportedClassVersionError: org/sonar/api/utils/SonarException : Unsupported major.minor version 52.0

This issue can be resolved by adding JDK version to 1.8 in POm.xml

Please apply the below fix in POM.xml
 
<build>
    <finalName>appname</finalName>
  <plugins>
  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
     <artifactId>maven-compiler-plugin</artifactId>
     <version>3.6.1</version>
     <configuration>
     <source>1.8</source>
     <target>1.8</target>
     </configuration>
  </plugin>
  <plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>sonar-maven-plugin</artifactId>
    <version>2.6</version>
  </plugin>
</plugins>
  </build>

Monday, October 9, 2017

Basic provisioning example of EC2 instance using Ansible on AWS

---
 - name: Basic provisioning example
   hosts: local
   connection: local
   gather_facts: False
   tags: provisioning

   vars:
     keypair: MyinfraCodeKey
     instance_type: t2.micro
     image: ami-916f59f4
     wait: yes
     group: webserver
     count: 1
     region: us-east-2
     security_group: ansible-webserver-1
   
   tasks:

     - name: Create a security group
       local_action: 
         module: ec2_group
         name: "{{ security_group }}"
         description: Security Group for webserver Servers
         region: "{{ region }}"
         rules:
            - proto: tcp
              from_port: 22
              to_port: 22
              cidr_ip: 0.0.0.0/0
            - proto: tcp
              from_port: 80
              to_port: 80
              cidr_ip: 0.0.0.0/0
            - proto: tcp
              from_port: 443
              to_port: 443
              cidr_ip: 0.0.0.0/0
         rules_egress:
            - proto: all
              cidr_ip: 0.0.0.0/0
       register: basic_firewall
     
     - name: Launch the new EC2 Instance
       local_action:  ec2 
                      group={{ security_group }} 
                      instance_type={{ instance_type}} 
                      image={{ image }} 
                      wait=true 
                      region={{ region }} 
                      keypair={{ keypair }}
                      count={{count}}
       register: ec2

     - name: Add the newly created EC2 instance(s) to the local host group (located inside the directory)
       local_action: lineinfile
                     dest="/etc/ansible/hosts"
                     regexp={{ item.public_ip }}
                     insertafter="[webserver]" line={{ item.public_ip }}
       with_items: "{{ ec2.instances }}"

Tuesday, September 26, 2017

How to install Apache Maven on Redhat Enterprise Linux Instance?

Here are the steps for installing Apache Maven on RHEL:
Make sure you install Java first by following below steps:

sudo yum -y install wget
sudo wget --no-check-certificate --no-cookies --header 'Cookie: oraclelicense=accept-securebackup-cookie' 'http://download.oracle.com/otn-pub/java/jdk/8u141-b15/336fa29ff2bb4ef291e347e091f7f4a7/jdk-8u141-linux-x64.rpm'
sudo rpm -i jdk-8u141-linux-x64.rpm

Now steps for installing Apache Maven:
sudo wget http://repos.fedorapeople.org/repos/dchen/apache-maven/epel-apache-maven.repo -O /etc/yum.repos.d/epel-apache-maven.repo
sudo sed -i s/\$releasever/6/g /etc/yum.repos.d/epel-apache-maven.repo
sudo yum install -y apache-maven
mvn --version

the above command should print the below message:

Apache Maven 3.5.2 (138edd61fd100ec658bfa2d307c43b76940a5d7d; 2017-10-18T07:58:13Z)
Maven home: /usr/share/apache-maven
Java version: 1.7.0_181, vendor: Oracle Corporation
Java home: /usr/lib/jvm/java-1.7.0-openjdk-1.7.0.181-2.6.14.8.el7_5.x86_64/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "3.10.0-862.el7.x86_64", arch: "amd64", family: "unix"

Tuesday, September 12, 2017

How to change default port number in Sonatype Nexus 2? - Change default port number in SonaType Nexus 2

The default port number for Sonatype Nexus is 8081. It can be changed though.
If you would like to change it, modify in below location:
$install-dir/etc/org.sonatype.nexus.cfg file
application-port=8082

Click here to see steps for how to install Nexus on Redhat.
Click here to see steps for how to install Nexus on Ubuntu.