Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion jenkins/Jenkinsfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

pipeline {
agent any
stages {
Expand All @@ -20,11 +21,13 @@ pipeline {
steps {
sh './jenkins/scripts/deliver.sh'
}

}
stage('Complete') {
steps {
echo 'Job Complete!'
echo 'Job Complete - The Pipeline has Finished!'
}
}

}
}
27 changes: 4 additions & 23 deletions jenkins/scripts/deliver.sh
Original file line number Diff line number Diff line change
@@ -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 <name/> element'
echo 'within <project/> 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 <version/> element within <project/> 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
22 changes: 19 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
<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">
<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.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>my-app</name>
<url>http://maven.apache.org</url>

<dependencies>
<dependency>
<groupId>junit</groupId>
Expand All @@ -15,14 +17,28 @@
<scope>test</scope>
</dependency>
</dependencies>

<build>
<finalName>my-app</finalName>
<plugins>
<plugin>
<!-- Build an executable JAR -->
<!-- Ensure correct Java version -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>8</source>
<target>8</target>
</configuration>
</plugin>

<plugin>
<!-- Build an executable JAR with a fixed name -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
<configuration>
<finalName>my-app</finalName> <!-- Ensures JAR is named my-app.jar -->
<archive>
<manifest>
<addClasspath>true</addClasspath>
Expand Down
1 change: 1 addition & 0 deletions simple-java-maven-app
Submodule simple-java-maven-app added at 1c3d17
30 changes: 30 additions & 0 deletions test.jenkinsfile
Original file line number Diff line number Diff line change
@@ -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!'
}
}
}
}