diff --git a/.gitignore b/.gitignore index 7a3e2fd..63fb63b 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,8 @@ # Crash log files crash.log + + # Ignore any .tfvars files that are generated automatically for each Terraform run. Most # .tfvars files are managed as part of configuration and so should be included in # version control. @@ -27,3 +29,34 @@ override.tf.json # Include tfplan files to ignore the plan output of command: terraform plan -out=tfplan # example: *tfplan* + +# Created by https://www.toptal.com/developers/gitignore/api/java +# Edit at https://www.toptal.com/developers/gitignore?templates=java + +### Java ### +# Compiled class file +*.class + +# Log file +*.log + +# BlueJ files +*.ctxt + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +*.jar +*.war +*.nar +*.ear +*.zip +*.tar.gz +*.rar + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* +replay_pid* + +# End of https://www.toptal.com/developers/gitignore/api/java diff --git a/.project b/.project new file mode 100644 index 0000000..448d6b2 --- /dev/null +++ b/.project @@ -0,0 +1,34 @@ + + + my-app + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.jdt.core.javanature + org.eclipse.m2e.core.maven2Nature + + + + 1675155637774 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/README.md b/README.md index a6b49c4..7d933e7 100644 --- a/README.md +++ b/README.md @@ -1,87 +1,107 @@ -# Jenkins-cicd -PG DO - CI/CD Pipeline with Jenkins Simplilearn - -# AWS Ubuntu VM Provisioning steps -- Step 1: Click on Launch Instance -- Step 2 : Click on Software Image (AMI) -- Select Ubuntu -- Step 4: Key pair name – required -- Click on Create new key pair -- Put key pair name Jenkins-sl -- & Download it -- Step 5 : Click on Launch Instance -- Step 6 : Select your VM and Click connect -- Step 7 : You can see the terminal -- Step: Showing Github example - -# Git Status -``` -git --version -``` -## cretae Dir -``` -mkdir demo -cd demo -``` -## GIT & Ubuntu SSH connection -``` -ssh-keygen +# Java +## References: +- https://maven.apache.org/guides/getting-started/maven-in-five-minutes.html + + +⦁ Build with Maven option in jenkins + +⦁ pom.xml file required -"Hit enter button 3 time" +⦁ Commands + +# Creating a Project +You need somewhere for your project to reside. Create a directory somewhere and start a shell in that directory. On your command line, execute the following Maven goal: -cat ~/.ssh/id_rsa.pub -git clone git@github.com:manikcloud/Jenkins-cicd.git -history -history | cut -c 8- ``` +mvn archetype:generate -DgroupId=com.mycompany.app -DartifactId=my-app -DarchetypeArtifactId=maven-archetype-quickstart -DarchetypeVersion=1.4 -DinteractiveMode=false -# JENKINS INSTALLATION on UBUNTU 18.04, for Ubunt 22.04 please skip the step 3 & 4 ``` -sudo apt-get update -sudo apt install openjdk-8-jdk -sudo wget -q -O - https://pkg.jenkins.io/debian/jenkins.io.key | sudo apt-key add -sudo sh -c 'echo deb http://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list' -sudo apt-get update -sudo apt install jenkins -sudo /etc/init.d/jenkins start -service jenkins status -sudo cat /var/lib/jenkins/secrets/initialAdminPassword -history | cut -c 8- + +You will notice that the generate goal created a directory with the same name given as the artifactId. Change into that directory. ``` -# Jenkins URL with port 8080 -- http://x.x.x.x:8080/ +cd my-app -replace x with your ip +``` -# Change Security group rule for Jenkins +## Build the Project ``` -- Select your instance -- Down below select your security tab -- Click on the Security groups sg-0c51908b5fa4abf75 (launch-wizard-2) -- Click on the action -- Click on EDIT INBOUND RULE -- Select custom TCP and put port 8080 -- Custom ip should be 0.0.0.0/0 -- Click on Save the rule +mvn package + ``` -# common error +- validate +- generate-sources +- process-sources +- generate-resources +- process-resources +- compile + +You may test the newly compiled and packaged JAR with the following command: ``` -getting "E: Unable to locate package openjdk-8-jdk" message on java update +java -cp target/my-app-1.0-SNAPSHOT.jar com.mycompany.app.App +Which will print the quintessential: ``` +Hello World! + +# Lesson 3 Demo 3: Maven Setup + +This section will guide you to: +⦁ Configure build tools and JDK versions -# Resolution -Run this command +This lab has two sub-sections, namely: +⦁ Configuring the Maven setup +⦁ Configuring the JDK + +## Step 1: Configuring the Maven setup +⦁ Open the terminal and go to Jenkins dashboard by typing localhost:8081 in your browser +⦁ Click on Manage Jenkins. From the list of options, choose Manage Plugins. + + +⦁ Under the Available tab, select Maven Integration + + +⦁ Click on Install without restart and the plugin will be installed + + + +⦁ Go to https://maven.apache.org/download.cgi and download the binary zip file + + +⦁ Unzip and extract the file and copy the path. ``` -sudo apt update +$ cd /home/labsuser/Downloads +$ unzip apache-maven-3.6.3-bin.zip ``` -# Plugin Installation -dashboard>manage>jenkins>manage plugins>maven integration +⦁ Go to Manage Jenkins from the Jenkins dashboard and select Global Tool Configuration + +⦁ Scroll down to the Maven section and click on Add Maven + +⦁ You can choose to install automatically by ticking the checkbox and specifying the version, or uncheck the box and enter the local path if you want to configure manually. + +⦁ Enter a name for the installation (For Example: my_maven) + +⦁ Uncheck the Install automatically checkbox. + +⦁ Paste the path to the Maven file in the MAVEN_HOME field (/home/labsuser/Downloads/apache-maven-3.6. + +⦁ click Save + + +⦁ You can now find Maven project as an option under New Item. + + + + +## Step 2: Configuring the JDK +⦁ Go to Manage Jenkins from the Jenkins dashboard and select Global Tool Configuration + +⦁ Scroll down to the JDK Section and click on Add JDK + +⦁ You can choose to install automatically by ticking the checkbox and specifying the version. Uncheck the box if you want to enter the JDK path manually -# References: -1. https://maven.apache.org/guides/getting-started/maven-in-five-minutes.html -2. https://maven.apache.org/download.cgi + +⦁ Enter the path to the JDK in the JAVA_HOME field (/usr/lib/jvm/java-8-openjdk-amd64/) and click Save diff --git a/history.txt b/history.txt deleted file mode 100644 index 850e06e..0000000 --- a/history.txt +++ /dev/null @@ -1,170 +0,0 @@ - 1 clear - 2 pwd - 3 apt udate - 4 apt update - 5 sudo apt update - 6 cat /etc/os-release - 7 ping fb.com - 8 mkdir demom - 9 mkdir demo - 10 cd demo - 11 git - 12 git -version - 13 git --version - 14 ls -a - 15 ll -a - 16 git init - 17 ll -a - 18 git status - 19 vim index.html - 20 git status - 21 git add . - 22 git status - 23 git commit -am"first file" - 24 git status - 25 git log - 26 vim index.html - 27 cat index.html - 28 git status - 29 git add . - 30 git status - 31 git commit -am"first file 1" - 32 git log - 33 cd .. - 34 ssh-keygen - 35 cd ~/.ssh/ - 36 ll - 37 cat id_rsa.pub - 38 cd - - 39 git clone git@github.com:manikcloud/Jenkins-cicd.git - 40 cat ~/.ssh/id_rsa.pub - 41 git clone git@github.com:manikcloud/Jenkins-cicd.git - 42 history - 43 history | cut -c 8- - 44 cd Jenkins-cicd/ - 45 vim README.md - 46 nano README.md - 47 git status - 48 git add . && git commit -am"adding readme" && git push - 49 nano README.md - 50 git add . && git commit -am"adding readme" && git push - 51 ll ~/.ssh/ - 52 cat ~/.ssh/id_rsa.pub - 53 ssh-keygen - 54 ll ~/.ssh/ - 55 ll - 56 rm varun * - 57 rm varun* - 58 ll - 59 git pull - 60 git status - 61 git rm . - 62 git status - 63 git rm README.md - 64 git status - 65 git rm pom.xml - 66 ll - 67 git status - 68 git restore --staged pom.xml - 69 ll - 70 cd .. - 71 rm -rf Jenkins-cicd/ - 72 git clone git@github.com:manikcloud/Jenkins-cicd.git - 73 cd Jenkins-cicd/ - 74 ll - 75 vi index.html - 76 git staus - 77 git status - 78 git add . - 79 git status - 80 git commit -am"adding index.html" - 81 git push - 82 vi README.md - 83 git pull - 84 vi README.md - 85 sudo apt install openjdk-8-jdk - 86 sudo wget -q -O - https://pkg.jenkins.io/debian/jenkins.io.key | sudo apt-key add - 87 sudo sh -c 'echo deb http://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list' - 88 sudo apt-get update - 89 sudo apt install jenkins - 90 sudo /etc/init.d/jenkins start - 91 service jenkins stgatus - 92 service jenkins status - 93 cat /var/lib/jenkins/secrets/initialAdminPassword - 94 sudo cat /var/lib/jenkins/secrets/initialAdminPassword - 95 history | cut -c 8- - 96 cd Jenkins-cicd/ - 97 vi README.md - 98 git add . && git commit -am"adding jenkins installtion step in readme" && git push - 99 vi README.md - 100 git add . && git commit -am"adding jenkins installtion step in readme" && git push - 101 git pull - 102 vi README.md - 103 ll -a - 104 rm .README.md.swp - 105 ll -a - 106 vim README.md - 107 git add . && git commit -am"adding jenkins installtion step in readme" && git push - 108 vim README.md - 109 git add . && git commit -am"adding jenkins installtion step in readme" && git push - 110 sudo cat /var/lib/jenkins/secrets/initialAdminPassword - 111 echo "varun" - 112 vim README.md - 113 git add . && git commit -am"adding jenkins installtion step in readme" && git push - 114 git config --global --edit - 115 git add . && git commit -am"adding jenkins installtion step in readme" && git push - 116 git push - 117 git pull - 118 vim README.md - 119 git add . && git commit -am"adding jenkins installtion step in readme" && git push - 120 git pull - 121 vim README.md - 122 mvn --version - 123 sudo apt install maven - 124 apt install tree - 125 sudo apt install tree - 126 which mvn - 127 mvn --version - 128 cd .. - 129 mvn archetype:generate -DgroupId=com.mycompany.app -DartifactId=my-app -DarchetypeArtifactId=maven-archetype-quickstart -DarchetypeVersion=1.4 -DinteractiveMode=false - 130 ll - 131 rm -rf my-app/ - 132 ll - 133 mvn archetype:generate -DgroupId=com.mycompany.app -DartifactId=my-app -DarchetypeArtifactId=maven-archetype-quickstart -DarchetypeVersion=1.4 -DinteractiveMode=false - 134 ll - 135 cd my-app/ - 136 ll - 137 tree - 138 mvn ppackage - 139 mvn package - 140 ll - 141 tree - 142 ll - 143 ll target/ - 144 java -cp target/my-app-1.0-SNAPSHOT.jar com.mycompany.app.App - 145 vim src/main/java/com/mycompany/app/App.java - 146 java -cp target/my-app-1.0-SNAPSHOT.jar com.mycompany.app.App - 147 mvn clean install - 148 java -cp target/my-app-1.0-SNAPSHOT.jar com.mycompany.app.App - 149 cd .. - 150 ll - 151 rm -rf Jenkins-cicd/ - 152 git clone git@github.com:manikcloud/Jenkins-cicd.git - 153 cd Jenkins-cicd/ - 154 ll - 155 whereis mvn - 156 cd .. - 157 wget https://dlcdn.apache.org/maven/maven-3/3.8.6/binaries/apache-maven-3.8.6-bin.tar.gz - 158 ll - 159 tar -xvzf apache-maven-3.8.6-bin.tar.gz - 160 ll - 161 cd apache-maven-3.8.6/ - 162 ll - 163 pwd - 164 whereis java - 165 whereis git - 166 which git - 167 which mvn - 168 pwd - 169 ll - 170 history > ../Jenkins-cicd/history.txt diff --git a/index.html b/index.html deleted file mode 100644 index b14df64..0000000 --- a/index.html +++ /dev/null @@ -1 +0,0 @@ -Hi diff --git a/src/main/java/com/mycompany/app/App.java b/src/main/java/com/mycompany/app/App.java index 77cf3e0..44c09dd 100644 --- a/src/main/java/com/mycompany/app/App.java +++ b/src/main/java/com/mycompany/app/App.java @@ -8,6 +8,6 @@ public class App { public static void main( String[] args ) { - System.out.println( "Hello World!" ); + System.out.println( "Hello World! From Varun Manik Simplilearn" ); } } diff --git a/target/classes/com/mycompany/app/App.class b/target/classes/com/mycompany/app/App.class deleted file mode 100644 index 5cc43ee..0000000 Binary files a/target/classes/com/mycompany/app/App.class and /dev/null differ diff --git a/target/maven-archiver/pom.properties b/target/maven-archiver/pom.properties deleted file mode 100644 index b1f1b69..0000000 --- a/target/maven-archiver/pom.properties +++ /dev/null @@ -1,4 +0,0 @@ -#Created by Apache Maven 3.6.0 -version=1.0-SNAPSHOT -groupId=com.mycompany.app -artifactId=my-app diff --git a/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst b/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst deleted file mode 100644 index de9dba0..0000000 --- a/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst +++ /dev/null @@ -1 +0,0 @@ -com/mycompany/app/App.class diff --git a/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst b/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst deleted file mode 100644 index 015d002..0000000 --- a/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst +++ /dev/null @@ -1 +0,0 @@ -/root/Jenkins-cicd/my-app/src/main/java/com/mycompany/app/App.java diff --git a/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst b/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst deleted file mode 100644 index 6348184..0000000 --- a/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst +++ /dev/null @@ -1 +0,0 @@ -com/mycompany/app/AppTest.class diff --git a/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst b/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst deleted file mode 100644 index cdee135..0000000 --- a/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst +++ /dev/null @@ -1 +0,0 @@ -/root/Jenkins-cicd/my-app/src/test/java/com/mycompany/app/AppTest.java diff --git a/target/my-app-1.0-SNAPSHOT.jar b/target/my-app-1.0-SNAPSHOT.jar deleted file mode 100644 index 392b6ff..0000000 Binary files a/target/my-app-1.0-SNAPSHOT.jar and /dev/null differ diff --git a/target/surefire-reports/TEST-com.mycompany.app.AppTest.xml b/target/surefire-reports/TEST-com.mycompany.app.AppTest.xml deleted file mode 100644 index 4b9c2b4..0000000 --- a/target/surefire-reports/TEST-com.mycompany.app.AppTest.xml +++ /dev/null @@ -1,60 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/target/surefire-reports/com.mycompany.app.AppTest.txt b/target/surefire-reports/com.mycompany.app.AppTest.txt deleted file mode 100644 index be9d8d3..0000000 --- a/target/surefire-reports/com.mycompany.app.AppTest.txt +++ /dev/null @@ -1,4 +0,0 @@ -------------------------------------------------------------------------------- -Test set: com.mycompany.app.AppTest -------------------------------------------------------------------------------- -Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.115 s - in com.mycompany.app.AppTest diff --git a/target/test-classes/com/mycompany/app/AppTest.class b/target/test-classes/com/mycompany/app/AppTest.class deleted file mode 100644 index 197784c..0000000 Binary files a/target/test-classes/com/mycompany/app/AppTest.class and /dev/null differ