diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 00000000..de183211 --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,72 @@ +pipeline { + agent { + docker { + image 'maven:3-alpine' + label 'aws-slave' + args '-v /root/.m2:/root/.m2' + } +} + options { + skipStagesAfterUnstable() + } + + stages { + + stage('Build') { + steps { + echo '-------Build Started mf--------' + git 'https://github.com/radjaafa/java-maven-junit-helloworld.git' + sh 'mvn -B -DskipTests clean package' + archiveArtifacts artifacts: 'target/*.jar', fingerprint:true + } + } + + stage('Test') { + steps { + sh 'mvn test' + sh 'mvn verify' + junit 'target/surefire-reports/*Test.xml' + junit 'target/failsafe-reports/*IT.xml' + } + + } + + stage('SCM') { + steps{ + git 'https://github.com/radjaafa/java-maven-junit-helloworld.git' + } + } + + stage('SonarQube Analysis') { + steps { + withSonarQubeEnv(installationName:'SonarQube') { + sh 'mvn org.sonarsource.scanner.maven:sonar-maven-plugin:3.6.0.1398:sonar' + } + } + } + + stage('Push'){ + steps{ + sshagent (credentials['jenkinsh']){ + sh 'scp -o StrictHostKeyChecking=no target/*.jar jenkins@3.125.242.200' + } + } + } + + stage("Quality Gate") { + steps { + echo '---------Quality Gate--------' + timeout(time: 5, unit: 'MINUTES') { + waitForQualityGate abortPipeline: true + } + } + } + + } + post { + success { + echo 'Build finished contrary to common sense' + } + } + +} diff --git a/build.sh b/build.sh new file mode 100755 index 00000000..25b27dc7 --- /dev/null +++ b/build.sh @@ -0,0 +1,26 @@ +#!/usr/bin/env bash + +echo 'The following Maven command installs your Maven-built Java application' +echo 'into the local Maven repository, which will ultimately be stored in' +echo 'Jenkins''s local Maven repository (and the "maven-repository" Docker data' +echo 'volume).' +set -x +mvn jar:jar install:install help:evaluate -Dexpression=project.name +set +x + +echo 'The following complex command extracts the value of the element' +echo 'within of your Java/Maven project''s "pom.xml" file.' +set -x +NAME=`mvn help:evaluate -Dexpression=project.name | grep "^[^\[]"` +set +x + +echo 'The following complex command behaves similarly to the previous one but' +echo 'extracts the value of the element within instead.' +set -x +VERSION=`mvn help:evaluate -Dexpression=project.version | grep "^[^\[]"` +set +x + +echo 'The following command runs and outputs the execution of your Java' +echo 'application (which Jenkins built using Maven) to the Jenkins UI.' +set -x +java -jar target/${NAME}-${VERSION}.jar diff --git a/pom.xml b/pom.xml index 1c0d7dda..6723be4e 100644 --- a/pom.xml +++ b/pom.xml @@ -171,7 +171,23 @@ - + + + + org.apache.maven.plugins + maven-jar-plugin + 3.1.0 + + + + true + lib/ + com.mypackage.MyClass + + + + +