×

Subversion Repository and Jenkins CICD

A combination of Subversion and jenkins make a development process more flexible and developers to give more stress in their development and implementation.

Subversion Repository and Jenkins CICD

Step 1: Creating CICD Instance

One can create a linux server through the creating virtual instances in Google Cloud Platform

Url: https://console.cloud.google.com

Steps - Compute Engine > VM Instances > Create new Instances

1.1 Installing Jenkins into the CICD Instance

For installing jenkins we need to install JDK to support the Jenkins

Enter into the SSH console to perform the task. Here we are making uat-server as a Jenkins remote.


1.1.1 Java Installation

Now install the Java first through the `apt-get` package manager. For this purpose, you will need to install open source implementation of JAVA Version 8. This is quite easy to do so by executing the command below.

apt-get install openjdk-8-jdk


When you execute the above command, it shows you the list of other recommended and required packages to be installed with Java `openjdk`. To proceed with those packages, you have to press `Y` or type `N` to exit the installer. It will take a few minutes to complete the Java installation. Once it is done, run the command below to check the installed version of Java on your system as shown.

java -version

1.1.2 Installing Nginx

Jenkins requires the basic web server installed on your system, so if you don’t have any of your web server installed on your operating system, you can execute the following command to install the web server.


apt-get install nginx


1.1.3 Jenkins Installation and Configuration

Now we are ready to install `Jenkins`. So before the package installation, we have to add the key and source list to apt for Jenkins. To do so, issue the following two commands in the terminal one by one


  1. wget -q -O - https://pkg.jenkins.io/debian/jenkins-ci.org.key | sudo apt-key add -
    You will get the `OK` status after you add the key. For the source list, here is the command to run.

  2. sudo sh -c 'echo deb http://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list'
    Now it needs to update `apt’s` cache before moving to Jenkins so that it can refresh the operating system’s repository for the latest packages.

  3. sudo apt-get update
    Once your system is updated, execute the command below for the installation of Jenkins and type the `Y` key to proceed with the installation process.

  4. sudo apt-get install jenkins
    The installation process will end up with starting its daemon. To check the status of Jenkins service, the command below will show you its status with running process ID. Jenkins service run with its default username `jenkin`.

  5. service jenkins status
    Jenkins Continuous Integration Server is running with the pid 16997


If you need to update the configurations of Jenkins as per your requirements, then you can find its configuration file under the `/etc/default/` directory and can make the changes. Jenkins runs on port 8080 by default for HTTP connector. Now let’s open your web browser to use its GUI. http://your-ip-address:8080


53.png

 

 1.2 Configuring Jenkins

To use and configure Jenkins, visit the following address in your local machine browser. Clicking the Manage Jenkins options follow the show settings:


 71.png


Step 2: Creating SVN Repository(server version)

2.1 Configuring SVN Repo with various users

First of all, you need to install Apache web server to access svn server using HTTP URLs. Skip this step if you already have Apache web server on your system. Run the following command:

sudo apt-get update
sudo apt-get install apache2

2.1.1 Install SVN Server

Use the following command to install subversion packages and their dependencies. Also, install svn module for Apache libapache2-mod-svn packages on your system

sudo apt-get install subversion libapache2-mod-svn libapache2-svn libsvn-dev


After installation, enable required Apache modules and restart Apache service.

sudo a2enmod dav
sudo a2enmod dav_svn
sudo service apache2 restart


2.1.2 Configure Apache with Subversion

Subversion Apache module package creates an configuration file /etc/apache2/mods-enabled/dav_svn.conf. You just need to make the necessary changes to it.

Alias /svn /var/lib/svn
<Location /svn>

  DAV svn
  SVNParentPath /var/lib/svn

  AuthType Basic
  AuthName "Subversion Repository"
  AuthUserFile /etc/apache2/dav_svn.passwd
  Require valid-user
    
</Location>

2.1.3 Create First SVN Repository

sudo mkdir -p /var/lib/svn/
sudo svnadmin create /var/lib/svn/myrepo
sudo chown -R www-data:www-data /var/lib/svn
sudo chmod -R 775 /var/lib/svn

2.1.4 Create Users for Subversion

sudo htpasswd -cm /etc/apache2/dav_svn.passwd admin

sudo htpasswd -cm /etc/apache2/dav_svn.passwd user1

sudo htpasswd -cm /etc/apache2/dav_svn.passwd user2

2.1.5 Access repository in Browser

http://your-ip-address/svn/myrepo/




Step 3:Installing TortoiseSVN on local(Client version)

https://osdn.net/projects/tortoisesvn/storage/1.10.1/Application/TortoiseSVN-1.10.1.28295-x64-svn-1.10.2.msi/

3.1 Installing VisualSVN Server for Accessing TortoiseSVN

https://www.visualsvn.com/files/VisualSVN-Server-3.9.1-x64.msi


3.2 Browsing the remote SVN Repository(server end)

Right-clicking on any window go to the following:









Paste the link of the  Repository URL and access the repository from local.

Step 4: Creating Files for Commit (Java Code)

Write a code in java for CICD. Create a folder and create a java file for execution.



class Demo{

public static void main(String args[]){

          for(int i=1;i<=10;i++){

System.out.println("Hello Welcome Mr.John for "+i);

         }

}

}


***Compile the file and you will get the .class file for the platform independency.


4.1 Commiting Files




Right click on that folder and click on the ‘SVN Commit’ give an appropriate commit message and click ‘Ok’

Check whether the files were pushed into the remote repository or not by browsing the remote repository (Step 3.2)



Step 5: Connecting Jenkins with SVN Remote Repository

5.1 Creating a Job in jenkins and configuring the job

To schedule your new jobs, click the `New Item` on the top left of your Jenkins Dashboard, then enter a name for the job and select `Freestyle Job`. Press OK to create a new Job.

Name your desired name of the particular job


121.png



In the credential management add the credential(s) created in Step 2





In the build section. Put the command which you want to execute. Here we want to execute the java program. Trigger the build on clicking the Build Now and check for the Console Output


Step 6: Controlling Versions with Tagging a build

Bibliography

https://www.youtube.com/watch?v=R0gyFokexks&t=131s

https://www.youtube.com/watch?v=wJ8p4ObTpjI

https://tecadmin.net/install-subversion-server-on-ubuntu/

https://websiteforstudents.com/install-jenkins-on-ubuntu-16-04-17-10-18-04-lts-server/





Trendy