diff --git a/jenkins/Jenkinsfile b/jenkins/Jenkinsfile index 52eed25843..e74921a14d 100644 --- a/jenkins/Jenkinsfile +++ b/jenkins/Jenkinsfile @@ -1,3 +1,4 @@ + pipeline { agent any stages { @@ -20,11 +21,13 @@ pipeline { steps { sh './jenkins/scripts/deliver.sh' } + } stage('Complete') { steps { - echo 'Job Complete!' + echo 'Job Complete - The Pipeline has Finished!' } } + } } diff --git a/jenkins/scripts/deliver.sh b/jenkins/scripts/deliver.sh index 25b27dc795..ebcefdf346 100755 --- a/jenkins/scripts/deliver.sh +++ b/jenkins/scripts/deliver.sh @@ -1,26 +1,7 @@ #!/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 +#!/bin/bash +set -e -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 +echo "Running the Java application..." +java -jar target/my-app.jar diff --git a/pom.xml b/pom.xml index 19ee4305a8..303aaf8888 100644 --- a/pom.xml +++ b/pom.xml @@ -1,5 +1,6 @@ - + 4.0.0 com.mycompany.app my-app @@ -7,6 +8,7 @@ 1.0-SNAPSHOT my-app http://maven.apache.org + junit @@ -15,14 +17,28 @@ test + + my-app - + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + 8 + 8 + + + + + org.apache.maven.plugins maven-jar-plugin 3.0.2 + my-app true diff --git a/simple-java-maven-app b/simple-java-maven-app new file mode 160000 index 0000000000..1c3d179154 --- /dev/null +++ b/simple-java-maven-app @@ -0,0 +1 @@ +Subproject commit 1c3d1791548e4e9de6ff1de25d461894ad085a7a diff --git a/test.jenkinsfile b/test.jenkinsfile new file mode 100644 index 0000000000..52eed25843 --- /dev/null +++ b/test.jenkinsfile @@ -0,0 +1,30 @@ +pipeline { + agent any + stages { + stage('Build') { + steps { + sh 'mvn -B -DskipTests clean package' + } + } + stage('Test') { + steps { + sh 'mvn test' + } + post { + always { + junit 'target/surefire-reports/*.xml' + } + } + } + stage('Deliver') { + steps { + sh './jenkins/scripts/deliver.sh' + } + } + stage('Complete') { + steps { + echo 'Job Complete!' + } + } + } +}