Tuesday, 1 September 2020

How to make Code changes directly in Bitbucket and remotely In your Project (local Machine)with Vscode

 steps to make a code change in Bitbucket to trigger builds in Jenkins and view results in Tomcat.


How to make sure code change to trigger automated build? you can do in one of two ways:

1. Make code changes directly in bitbucket which are given below:
2. change in your computer after cloning. refer to steps given in lab exercise #2

How to make code changes directly in bitbucket?

1. Go to https://www.bitbucket.org
2. Click on repo you had created earlier and configured in jenkins freestyle job or pipeline.
3. Click on MyWebApp
4. Click on src/main/webapp
5. Click on index.jsp
6. Click on Edit and make the change highlighted in yellow:

<html>
<body>
<h2>Hello Guys !!! Im a DevOps Engineer!</h2>
</body>
</html>
7. Commit (no need to create a pull request for this change)
8. Now this should have triggered automated build/deployment in Jenkins.
9. Go to browser, enter public dns name where tomcat is deployed to see output in the browser
10. Now you should see the output in the browser

Hello Guys !!! Im a DevOps Engineer!

Next Go to Your Project on you local machine

Right click and open Git Bash Here
Type code . to load the project into Vscode

Click on the Pull/push icon to get the latest changes from your repo
Navigate to MyWebApp--src--main--webapp and click on index.jsp. This is the main code of your web application
Edit the code. Add Devops is the Next best thing in IT!
Click file--- save

The Source control icon will indicate you have pending changes

Enter a commit message in the Message prompt the click the check symbol to save the commit and click Yes to Stage



You will notice there is 1 pending change to your local repo. Click the Push/Pull icon to update this changes to your remote repo
This will automatically push changes to your repo and trigger a new build in Jenkins.
Go to browser, enter public dns name where tomcat is deployed to see output in the browser
Now you should see the output in the browser

Devops is the Next best thing in IT!

Install SonarQube scanner,deploy to container,Jacoco Plugin and Automate your and Automate your First App Project in Jenkins

 


 

pre-requisites:

 

1.    Make sure you configure maven installation under Jenkins-->manage Jenkins-> Global Tool Configuration. under maven installation. enter Maven3 as name, enter path of maven installation --> /usr/share/maven and uncheck install automatically option.  Add JDK enter JDK8 as name , uncheck the box and enter path /usr/lib/jvm/java-8-openjdk-amd64



A




 

 




2. Also install SonarQube scanner,  deploy to container,  Jacoco plugins under Jenkins --> Manage Jenkins --> Manage plug-ins

Click on Available, type Sonarqube, select SonarQube scanner. Click on Install without restart.

 

Repeat same for deploy to container and jacoco

 

 

Click on without restart.

 

steps to automate MyWebApp project in Jenkins:

 

1. Login to Jenkins. Click on New item.

 

 

 

 

2. Enter an item name --> select Free style project. enter name as myFirstAutomateJob. click OK.

 

3. under source code mgmt, click git. enter bit bucket URL. go to Bitbucket, select repo you created from previous lab exercise , click on Clone and select HTTPS Url.

Copy it. 

 

 

 

 

 

under credentials --> click Add- > select Jenkins --> 

 

Also make sure to remove git clone trailing the url

 

 

 Username is your bitbucket username----> go to Bitbucket---Settings ----Personal Bitbucket Settings----Get your username----App password----Go To Api Token....Generate token. Use the Token as password












Select check all the Read boxes and click next




4. select that from drop down

Specify a branch or leave as default */master  or */main to build from master branch

 

.

5. under build trigger click on poll scm, enter this value to check 

for every 2 mins --> H/02 * * * *

 

6. Build --> Add build step --> invoke top level maven targets -->

 

 

 

select Maven3 from drop down

enter goals as --> clean install

 

 

 

 

 

7. Click on advanced, enter the path of POM file as --> MyWebApp/pom.xml

 

 

8. add Post build action - select archive the artifacts

 

enter the below value:(ignore if you get any error in red color)

 **/*.war

there may be some errors in red, but ignore it.

 

 

    9. click on Add post build action, select deploy war/ear to container

 

      enter the same value

**/*.war 

in WAR/EAR files, leave context path empty

 

   10. click on Add container , select Tomcat 8.x

   11. click on add credentials, enter tomcat/password as user name and password.

      select it from drop down.

   12. tomcat url should be http://localhost:8090

 

 

 

click Apply, click Save



click on build now..It should build. 



if there is any error, please check the console output.

Most of the common error would be checking the path of Maven installation, valid credentials for bitbucket or Tomcat. Also make sure you install the plug-ins.

 

After successful deployment, please make sure you check the output in Tomcat by going to browser and enter below URL


 http://public_dns_name_of_EC2:8090/MyWebApp

 

You should see Hello World!!!

 

                            Watch video Demonstration Below



 Troubleshooting Issues

Maven Build Failure

### Option 1 — Install JDK 8 (recommended for WAR projects)


Ubuntu/Debian:


sudo apt update

sudo apt install openjdk-8-jdk


Edit Tomcat

sudo vi /etc/default/tomcat9
Add the below line:


JAVA_HOME="/usr/lib/jvm/java-21-openjdk-amd64"

JRE_HOME="/usr/lib/jvm/java-21-openjdk-amd64"


sudo systemctl restart tomcat9

Bash Script to Install Artifactory in Ubuntu 22

JFrog Artifactory OSS 7.21.5 — Install (Bash Script) This script installs Artifactory OSS (no Docker, no Pro, works on Ubuntu 22 EC2). ...