Friday, 30 June 2017

Jenkins + Gitlab + AWS EC2 Deployment


Jenkins Gitlab configuration :

Go  to Gitlab --> User --> Settings --> Look for Access Tokens

Create a new Access Tokens for Jenkins


 Jenkins Configuration :

Add Gitlab token in Credentials



Add Publish over SSH plugin in Jenkins

Configure Hostname as a Remote Server IP Address
Configure Username as a Remote Server's Username
Key : Add Jenkins users private key




How  to Generate SSH key for Jenkins user on Jenkins System 

sudo su -s /bin/bash jenkins
ssh-keygen
cat /var/lib/jenkins/.ssh/id_rsa.pub
Copy key from id_rsa.pub
Paste the key in remote server's authorized key file

Jenkins Build Job Configuration :

Select Execute Shell :

#!/bin/bash
cd /home/g1/
. ./copy2ec2.sh


Copy2ec2  Script :

TIME=`date +%b-%d-%y`            
FILENAME=backup-$TIME.tar.gz

SRCDIR=/var/lib/jenkins/workspace/xxx/xxx
DESTDIR=/home/g1/joom_coode

tar -zcvf $DESTDIR/$FILENAME $SRCDIR --exclude .git --exclude /administrator/cache --exclude configuration.php  --exclude .gitignore --exclude .gitlab-ci.yml --exclude .htaccess  --exclude htaccess.txt --exclude robots.txt --exclude robots.txt.dist --exclude web.config.txt

echo "Uploading Artifacts on EC2...."
cd /home/g1/joom_coode
scp -r * xxx@x.210.x.x:/home/xxx/jen_deploy
rm -Rf *


Send Files or Execute commands over SSH

echo "Unpacking TAR...."
cd /home/xxx/jen_deploy

tar -zxvf backup-*.tar.gz

Sunday, 11 June 2017


Hybris 6.3 Build with Jenkins & Sonar


Jenkins Configuration :

JDK Configuration          :       JDK 1.8
Required Plugin               :       SonarQube Scanner for Jenkins
Sonar Qube Scanner        :      Install Automatically - 3.0.3
Jenkins Node Properties  :      Environment Variables 
                                                JAVA_OPTS 
                                               -XX:MaxPermSize=4g -Xms4g -Xms4g
                                                SONAR_SCANNER_OPTS 
                                               -Xmx2g -XX:MaxPermSize=4g
                                                MAVEN_OPTS
                                               -Xms256m -Xmx4096m -XX:+UseSerialGC

Hybris  Build & Sonar Configuration in Jenkins :
  • Configure GIT / SVN repository credentials to get the latest code from Repository
  • Execute Shell from Jenkins
echo "unpack Hybris platform ..."


#unzip "$HYBRIS_PACKAGE_DIR/HYBRISCOMM6300P_0-70002554.zip" -d "$WORKSPACE/"

#cd "$WORKSPACE" | ls -la
#cd "$WORKSPACE/hybris" | ls -la

#rm -rf "$WORKSPACE/hybris/config"
#rm -rf "$WORKSPACE/config"
#cp -Rf "/opt/hybris_63/hybris/" "$WORKSPACE/"

cp -Rf "$WORKSPACE/bin/custom" "$WORKSPACE/hybris/bin/"
cp -Rf "$WORKSPACE/config/local.properties" "$WORKSPACE/hybris/config"
cp -Rf "$WORKSPACE/config/localextensions.xml" "$WORKSPACE/hybris/config"

cd "$WORKSPACE/hybris/bin/platform"
. ./setantenv.sh
#ant -Dinput.template=develop
ant clean all

  • Execute Sonar Qube Scanner configuration in Jenkins 

Analysis Properties :

sonar.projectKey=lcw:master
sonar.projectName=LCW
sonar.projectVersion=1.0
sonar.sources=.
sonar.inclusions=config/**/*,bin/**/*



Jenkins and SonarQube on Single Host with Nginx 


Keep SonarQube run on its default port  9000

Nginx Configuration for Jenkins

server {

    listen 80;


    location / {


      proxy_set_header        Host $host:$server_port;

      proxy_set_header        X-Real-IP $remote_addr;
      proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header        X-Forwarded-Proto $scheme;

      # Fix the "It appears that your reverse proxy set up is broken" error.

      proxy_pass          http://127.0.0.1:8080;
      proxy_read_timeout  90;

      proxy_redirect      http://127.0.0.1:8080 http://172.21.26.20;


      # Required for new HTTP-based CLI

      proxy_http_version 1.1;
      proxy_request_buffering off;
    }
  }


Sonar Configuration :

Install Sonar as per below URL :

https://hostpresto.com/community/tutorials/how-to-install-sonarqube-continuous-inspection-on-ubuntu-14-04/

  • Setup MySQL Username & Password 
  • Create Sonarqube database in MySQL
Once above done start Sonar server. Try to browse Sonar URL http://<Server IP address>:9000/

Jenkins Configuration :

Install Plugin - SonarQube Scanner 
                         SonarQube Servers
                         SonarQube Graph

Create Authentication Token in SonarQube --> MyAccont-->Security