How to create a new Jenkins job for the server

From PheonixSolutions
Jump to navigation Jump to search

How to create a new Jenkins job for the server

What is Jenkins?

Jenkins is a tool that is used for automation, and it is an open-source server that allows all the developers to build, test and deploy software. It works or runs on Java as it is written in Java. Using Jenkins, we can continuously integrate projects(jobs) or end-to-endpoint automation.

Let us discuss this tool's necessity before proceeding to the installation's procedural part. Nowadays, humans are becoming lazy every day, so even having digital screens and just one click of a button in front of us also needs some automation. Here, I’m referring to that part of automation where we need not have to look upon a process(here called a job) for completion and after it does another job. For that, we have Jenkins with us.

Step 1: Create A record for the domain

 Example.com - IP for A record is 125.00.123.111

Step 2: Log in to the server

 ssh root@IP_Address -p Port_number

Step 3: Create a web server configuration file for this domain.

 Vi /etc/apache2/sites-available/example.com.conf

After opening the conf file edit the domain name and document root

 <VirtualHost *:80>
 ServerName milta.pheonixsolutions.com
 #ServerAlias www.milta.pheonixsolutions.com
 ServerAdmin admin-mail@localhost
 DocumentRoot /var/www/html/milta.pheonixsolutions.com
 <Directory /var/www/html/milta.pheonixsolutions.com>
 Options Indexes FollowSymLinks MultiViews
 AllowOverride All
 Require all granted
 #RewriteEngine on
 #Don't rewrite files or directories
 RewriteCond %{REQUEST_FILENAME} -f [OR]
 RewriteCond %{REQUEST_FILENAME} -d
 RewriteRule ^ - [L]
 #Rewrite everything else to index.html to allow HTML5 state links
 RewriteRule ^ index.html [L]
 </Directory>
 ErrorLog ${APACHE_LOG_DIR}/error.log
 CustomLog ${APACHE_LOG_DIR}/access.log combined
 RewriteEngine on
 RewriteCond %{SERVER_NAME} =milta.pheonixsolutions.com
 RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
 </VirtualHost>

Once it is completed press ESC save file and press this command:Wq!

Step 4: Go to the document’s root path

After that go to the document’s root path and create one application directory

 mkdir example.com

Step 5: Check the Apache syntax

Apache will analyze the configuration files and report any syntax errors or warnings. If your configuration is valid, you will see a message indicating that the syntax is OK.

If there are any errors or warnings, the command will provide information about the specific problem and the file in which it occurs. You will need to review the Apache configuration files mentioned in the error message to correct the issues.

 sudo apachectl -t

Step 6: Restart Apache to apply the changes

 sudo service apache2 restart

Step 7: Log in to the Jenkins

  1. Go to the dashboard

  2. And go to the new item

Step 8:

Enter the domain or any other name for your identification

Step 9:

If you want a new item, Skip the option and click OK.

Frontend procedure

Step 10: choice parameter

  1. Give name option Branch

  2. And choices give the main

Step 11: source code management

  1. Select the git option

  2. Repositories option gives a git URL on the repository URL

  3. Remaining automatically fill the option

Step 12: Build

  1. Change the server on which you're doing the Jenkins job to that IP address and username.

  2. Please give the document root to the following IP address.

  3. Before the username, give the build name or your endpoint name

Step 13: post-build actions

Give the save option

Backend procedure

Step 14: string parameter

  1. Give name option Branch

  2. And default value gives the development

Step 15: source code management

  1. Select the git option

  2. Repositories option gives a git URL on the repository URL

  3. Remaining automatically fill the option

Step 16: Build

  1. Change the server on which you're doing the Jenkins job to that IP address and username.

  2. After the IP address, Please give the document root on the command 

  3. The below line gives the port number, key username, and IP address, opens the directory, and the same document root gives the npm install.

  4. And again, below the lines, give the port number, key username, and IP address, and give PM2 restart 0.

  1. Before the username, give the build name or your endpoint name

Step 17: post-build actions

Give the save option

Step 18: Build with parameters

  1. After saving the Jenkins, come to milta.pheonixsolutions and press build with parameters

  2. Important one it both

  3. Select the main branch and give built It takes 10 seconds, please wait

  4. Go to status

Step 19: Status

  1. Go to the status it shows the green right symbol, which means it was successfully created the Jenkins job.

  2. Otherwise, it shows a red cross mark that is a failure, and Jenkins wants to recheck or check the server configuration file.

  3. Check console output it shows finished success

  4. Other it shows finished failed

Step 20: Conclusion

  1. After completing the Jenkins job it shows successful the console output

  2. Once you check the domain URL in the browser It shows the webpage on the browser

  3. Successfully completed the Jenkins job