-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit c545866
Showing
11 changed files
with
299 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Auto detect text files and perform LF normalization | ||
* text=auto |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
.DS_Store | ||
target/ | ||
pom.xml.tag | ||
pom.xml.releaseBackup | ||
pom.xml.versionsBackup | ||
pom.xml.next | ||
release.properties | ||
dependency-reduced-pom.xml | ||
buildNumber.properties | ||
.mvn/timing.properties | ||
|
||
# Avoid ignoring Maven wrapper jar file (.jar files are usually ignored) | ||
!/.mvn/wrapper/maven-wrapper.jar | ||
.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
node { | ||
stage('Configure') { | ||
env.PATH = "${tool 'maven-3.3.9'}/bin:${env.PATH}" | ||
version = '1.0.' + env.BUILD_NUMBER | ||
currentBuild.displayName = version | ||
|
||
properties([ | ||
buildDiscarder(logRotator(artifactDaysToKeepStr: '', artifactNumToKeepStr: '', daysToKeepStr: '', numToKeepStr: '10')), | ||
[$class: 'GithubProjectProperty', displayName: '', projectUrlStr: 'https://github.com/taz-jt/simple-java-maven-app/'], | ||
pipelineTriggers([[$class: 'GitHubPushTrigger']]) | ||
]) | ||
} | ||
|
||
stage('Checkout') { | ||
git 'https://github.com/taz-jt/simple-java-maven-app' | ||
} | ||
|
||
/* | ||
stage('Version') { | ||
sh "echo \'\ninfo.build.version=\'$version >> src/main/resources/application.properties || true" | ||
sh "mvn -B -V -U -e versions:set -DnewVersion=$version" | ||
} | ||
*/ | ||
|
||
stage('Build') { | ||
sh 'mvn -B -DskipTests clean package' | ||
} | ||
|
||
stage('Test') { | ||
sh 'mvn test' | ||
} | ||
|
||
stage('Archive') { | ||
junit allowEmptyResults: true, testResults: '**/target/**/TEST*.xml' | ||
} | ||
|
||
/* | ||
stage('Deploy') { | ||
// Depends on the 'Credentials Binding Plugin' | ||
// (https://wiki.jenkins-ci.org/display/JENKINS/Credentials+Binding+Plugin) | ||
withCredentials([[$class : 'UsernamePasswordMultiBinding', credentialsId: 'cloudfoundry', | ||
usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD']]) { | ||
sh ''' | ||
curl -L "https://cli.run.pivotal.io/stable?release=linux64-binary&source=github" | tar -zx | ||
./cf api https://api.run.pivotal.io | ||
./cf auth $USERNAME $PASSWORD | ||
./cf target -o bertjan-demo -s development | ||
./cf push | ||
''' | ||
} | ||
} | ||
*/ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
pipeline { | ||
agent { | ||
docker { | ||
image 'maven:3-alpine' | ||
args '-v /root/.m2:/root/.m2' | ||
} | ||
} | ||
options { | ||
skipStagesAfterUnstable() | ||
} | ||
stages { | ||
stage('Build') { | ||
steps { | ||
sh 'mvn -B -DskipTests clean package' | ||
} | ||
} | ||
stage('Test') { | ||
steps { | ||
sh 'mvn test' | ||
} | ||
post { | ||
always { | ||
junit 'target/surefire-reports/*.xml' | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# simple-java-maven-app | ||
|
||
This repository is for the | ||
[Build a Java app with Maven](https://jenkins.io/doc/tutorials/build-a-java-app-with-maven/) | ||
tutorial in the [Jenkins User Documentation](https://jenkins.io/doc/). | ||
|
||
The repository contains a simple Java application which outputs the string | ||
"Hello world!" and is accompanied by a couple of unit tests to check that the | ||
main application works as expected. The results of these tests are saved to a | ||
JUnit XML report. | ||
|
||
The `jenkins` directory contains an example of the `Jenkinsfile` (i.e. Pipeline) | ||
you'll be creating yourself during the tutorial and the `scripts` subdirectory | ||
contains a shell script with commands that are executed when Jenkins processes | ||
the "Deliver" stage of your Pipeline. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
pipeline { | ||
agent { | ||
docker { | ||
image 'maven:3-alpine' | ||
args '-v /root/.m2:/root/.m2' | ||
} | ||
} | ||
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' | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4"> | ||
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_6"> | ||
<output url="file://$MODULE_DIR$/target/classes" /> | ||
<output-test url="file://$MODULE_DIR$/target/test-classes" /> | ||
<content url="file://$MODULE_DIR$"> | ||
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" /> | ||
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" /> | ||
<excludeFolder url="file://$MODULE_DIR$/target" /> | ||
</content> | ||
<orderEntry type="inheritedJdk" /> | ||
<orderEntry type="sourceFolder" forTests="false" /> | ||
<orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.11" level="project" /> | ||
<orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" /> | ||
</component> | ||
</module> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<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> | ||
<artifactId>junit</artifactId> | ||
<version>4.11</version> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<!-- Build an executable JAR --> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>3.8.1</version> | ||
<configuration> | ||
<source>1.6</source> | ||
<target>1.6</target> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-jar-plugin</artifactId> | ||
<version>3.2.0</version> | ||
<configuration> | ||
<archive> | ||
<manifest> | ||
<addClasspath>true</addClasspath> | ||
<classpathPrefix>lib/</classpathPrefix> | ||
<mainClass>com.mycompany.app.App</mainClass> | ||
</manifest> | ||
</archive> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.mycompany.app; | ||
|
||
/** | ||
* Hello world! | ||
*/ | ||
public class App | ||
{ | ||
|
||
private final String message = "Hello World!"; | ||
|
||
public App() {} | ||
|
||
public static void main(String[] args) { | ||
System.out.println(new App().getMessage()); | ||
} | ||
|
||
private final String getMessage() { | ||
return message; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package com.mycompany.app; | ||
|
||
import java.io.ByteArrayOutputStream; | ||
import java.io.PrintStream; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.After; | ||
import static org.junit.Assert.*; | ||
|
||
/** | ||
* Unit test for simple App. | ||
*/ | ||
public class AppTest | ||
{ | ||
|
||
private final ByteArrayOutputStream outContent = new ByteArrayOutputStream(); | ||
|
||
@Before | ||
public void setUpStreams() { | ||
System.setOut(new PrintStream(outContent)); | ||
} | ||
|
||
@Test | ||
public void testAppConstructor() { | ||
try { | ||
new App(); | ||
} catch (Exception e) { | ||
fail("Construction failed."); | ||
} | ||
} | ||
|
||
@Test | ||
public void testAppMain() | ||
{ | ||
App.main(null); | ||
try { | ||
assertEquals("Hello World!" + System.getProperty("line.separator"), outContent.toString()); | ||
} catch (AssertionError e) { | ||
fail("\"message\" is not \"Hello World!\""); | ||
} | ||
} | ||
|
||
@After | ||
public void cleanUpStreams() { | ||
System.setOut(null); | ||
} | ||
|
||
} |