Showing posts with label plugin. Show all posts
Showing posts with label plugin. Show all posts

Tuesday, 1 September 2020

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.  


A




 

 





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

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

 

Repeat same for deploy to container 

 

 

Click on without restart.

 

Upgrade your Pom from Legacy jdk 8 to more mordern jdk 21

Go to Bitbucket....Source...MyWebApp....pom.xml




Delete everything in the pom.xml and replace it with the below

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
                             http://maven.apache.org/maven-v4_0_0.xsd">

    <modelVersion>4.0.0</modelVersion>

    <groupId>com.mywebapp</groupId>
    <artifactId>mywebapp</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>war</packaging>

    <name>MyWebApp</name>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <!-- Java version used for compilation -->
        <maven.compiler.source>21</maven.compiler.source>
        <maven.compiler.target>21</maven.compiler.target>
        <sonar.java.source>21</sonar.java.source>
        <sonar.java.target>21</sonar.java.target>
    </properties>
    <dependencies>
     
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-api</artifactId>
            <version>5.10.0</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-engine</artifactId>
            <version>5.10.0</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
    <build>
        <finalName>MyWebApp</finalName>

        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.11.0</version>
                <configuration>
                    <release>21</release>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>3.4.0</version>
            </plugin>
            <plugin>
                <groupId>org.sonarsource.scanner.maven</groupId>
                <artifactId>sonar-maven-plugin</artifactId>
                <version>5.2.0.4988</version>
            </plugin>

        </plugins>
    </build>

</project>



Click Commit


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

 


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



 

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

BashScript to disable non performing Jenkins Plugin (Cure Slowness- Make Jenkins Fast Again)

   Here’s a portable bash script to disable the nonessential plugins we turned off (mercurial, theme-manager, dark-theme, pipeline-graph-vie...