49 Commits

Author SHA1 Message Date
Nana Janashia
b739431651 Update Jenkinsfile 2021-03-21 13:40:15 +00:00
Nana Janashia
b78ed1bcf6 Update Jenkinsfile 2021-03-21 13:21:51 +00:00
Nana Janashia
00154a9e93 Update Jenkinsfile 2021-03-21 12:44:54 +00:00
Nana Janashia
df13897a25 Update Jenkinsfile 2021-03-21 11:11:15 +00:00
Nana Janashia
94db5c3efa Update Jenkinsfile 2021-03-21 10:20:42 +00:00
Nana Janashia
17291abd2e Update Jenkinsfile 2021-03-21 10:18:40 +00:00
Nana Janashia
d72a06f005 Update Jenkinsfile 2021-03-21 09:56:30 +00:00
Nana Janashia
0bd74fa092 Update Application.java 2021-03-21 09:56:06 +00:00
Nana Janashia
ac5c2b2106 Update Application.java 2021-03-21 09:48:22 +00:00
Nana Janashia
ddce6d49ac Update Jenkinsfile 2021-03-21 09:45:31 +00:00
Nana Janashia
ba406dd3a9 Update Jenkinsfile 2021-03-21 09:44:40 +00:00
Nana Janashia
997013ad3f Update Jenkinsfile 2021-03-21 08:55:14 +00:00
Nana Janashia
9fb3cfce01 Update Jenkinsfile 2021-03-21 08:53:32 +00:00
Nana Janashia
58f1a5cf3e Update Jenkinsfile 2021-03-21 08:44:59 +00:00
Nana Janashia
ee4f86c17a Update Jenkinsfile 2021-03-21 08:42:31 +00:00
Nana Janashia
94609f4347 Update Jenkinsfile 2021-03-21 08:40:58 +00:00
Nana Janashia
b10e682c11 Update Jenkinsfile 2021-03-21 08:30:52 +00:00
Nana Janashia
12135903ab Update Jenkinsfile 2021-03-21 08:21:44 +00:00
Nana Janashia
982fdd2438 Update Jenkinsfile 2021-03-21 08:20:13 +00:00
Nana Janashia
df3a84426f Update Jenkinsfile 2021-03-21 08:15:07 +00:00
Nana Janashia
b39bdc130f adjustments 2020-11-22 09:25:55 +01:00
Nana Janashia
7002a942d3 adjustments 2020-11-22 09:24:54 +01:00
Nana Janashia
5ee75f88dd Update Jenkinsfile 2020-11-18 12:44:07 +00:00
Nana Janashia
6a2de89154 Update Jenkinsfile 2020-11-18 12:15:37 +00:00
Nana Janashia
f6850fa35f Update Jenkinsfile 2020-11-18 12:10:01 +00:00
Nana Janashia
31ecf84171 Update Jenkinsfile 2020-11-18 12:08:28 +00:00
Nana Janashia
9b90eae493 Update Jenkinsfile 2020-11-18 12:01:49 +00:00
Nana Janashia
4056c657d3 Update Jenkinsfile 2020-11-18 12:00:08 +00:00
Nana Janashia
a5ed743178 Update Jenkinsfile 2020-11-18 11:59:09 +00:00
Nana Janashia
8afb0e62a3 Update Jenkinsfile 2020-11-12 09:42:08 +00:00
Nana Janashia
2b4921b5c8 Update Jenkinsfile 2020-11-12 09:37:37 +00:00
Nana Janashia
4f06b352e5 Update Jenkinsfile 2020-11-12 09:36:25 +00:00
Nana Janashia
c425e899d4 Update Jenkinsfile 2020-11-11 18:39:09 +00:00
Nana Janashia
15d6bf124f Update Jenkinsfile 2020-11-11 18:33:19 +00:00
Nana Janashia
b1440f702b Update Jenkinsfile 2020-11-11 16:55:32 +00:00
Nana Janashia
90bb5d1ddf Update Jenkinsfile 2020-11-11 16:46:57 +00:00
Nana Janashia
302893976c Update Jenkinsfile 2020-11-11 16:46:22 +00:00
Nana Janashia
a4a55e133b Update Jenkinsfile 2020-11-11 16:45:14 +00:00
Nana Janashia
9969d8b2cf Update Jenkinsfile 2020-11-06 12:49:54 +00:00
Nana Janashia
3e129808aa Update Jenkinsfile 2020-11-06 12:40:11 +00:00
Nana Janashia
f03d95e413 Update Jenkinsfile 2020-11-06 12:38:49 +00:00
Nana Janashia
c8f9061ef6 Update Jenkinsfile 2020-11-06 12:38:24 +00:00
Nana Janashia
6804a58c01 Update Jenkinsfile 2020-11-06 12:36:28 +00:00
Nana Janashia
5ef50d2628 Update Jenkinsfile 2020-11-06 12:35:52 +00:00
Nana Janashia
1c02e35f97 Update Jenkinsfile 2020-11-06 12:33:08 +00:00
Nana Janashia
f298808592 Update Jenkinsfile 2020-11-06 12:32:13 +00:00
Nana Janashia
a14a9d4f9a Update Jenkinsfile 2020-11-06 12:24:57 +00:00
Nana Janashia
d267e0d112 Update Jenkinsfile 2020-10-31 15:31:43 +00:00
Nana Janashia
833dd401b3 Add new file 2020-10-31 15:27:05 +00:00
11 changed files with 7 additions and 215 deletions

2
.gitignore vendored
View File

@@ -1,2 +1,2 @@
.idea/* .idea/*
target target/

View File

@@ -1,8 +0,0 @@
FROM openjdk:8-jre-alpine
EXPOSE 8080
COPY ./target/java-maven-app-*.jar /usr/app/
WORKDIR /usr/app
CMD java -jar java-maven-app-*.jar

58
Jenkinsfile vendored
View File

@@ -2,73 +2,25 @@
pipeline { pipeline {
agent any agent any
tools {
maven 'Maven'
}
environment {
ECR_REPO_URL = '664574038682.dkr.ecr.eu-west-3.amazonaws.com'
IMAGE_REPO = "${ECR_REPO_URL}/java-maven-app"
}
stages { stages {
stage('increment version') { stage('test') {
steps { steps {
script { script {
echo 'incrementing app version...' echo "Testing the application..."
sh 'mvn build-helper:parse-version versions:set \
-DnewVersion=\\\${parsedVersion.majorVersion}.\\\${parsedVersion.minorVersion}.\\\${parsedVersion.nextIncrementalVersion} \
versions:commit'
def matcher = readFile('pom.xml') =~ '<version>(.+)</version>'
def version = matcher[0][1]
env.IMAGE_NAME = "$version-$BUILD_NUMBER"
echo "############ ${IMAGE_REPO}"
} }
} }
} }
stage('build app') { stage('build') {
steps { steps {
script { script {
echo "building the application..." echo "Building the application..."
sh 'mvn clean package'
}
}
}
stage('build image') {
steps {
script {
echo "building the docker image..."
withCredentials([usernamePassword(credentialsId: 'ecr-credentials', passwordVariable: 'PASS', usernameVariable: 'USER')]) {
sh "docker build -t ${IMAGE_REPO}:${IMAGE_NAME} ."
sh "echo $PASS | docker login -u $USER --password-stdin ${ECR_REPO_URL}"
sh "docker push ${IMAGE_REPO}:${IMAGE_NAME}"
}
} }
} }
} }
stage('deploy') { stage('deploy') {
environment {
AWS_ACCESS_KEY_ID = credentials('jenkins_aws_access_key_id')
AWS_SECRET_ACCESS_KEY = credentials('jenkins_aws_secret_access_key')
APP_NAME = 'java-maven-app'
}
steps { steps {
script { script {
echo 'deploying docker image...' echo "Deploying the application..."
sh 'envsubst < kubernetes/deployment.yaml | kubectl apply -f -'
sh 'envsubst < kubernetes/service.yaml | kubectl apply -f -'
}
}
}
stage('commit version update') {
steps {
script {
withCredentials([usernamePassword(credentialsId: 'gitlab-credentials', passwordVariable: 'PASS', usernameVariable: 'USER')]) {
sh 'git config user.email "jenkins@example.com"'
sh 'git config user.name "Jenkins"'
sh "git remote set-url origin https://${USER}:${PASS}@gitlab.com/nanuchi/java-maven-app.git"
sh 'git add .'
sh 'git commit -m "ci: version bump"'
sh 'git push origin HEAD:jenkins-jobs'
}
} }
} }
} }

View File

@@ -1,24 +0,0 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: $APP_NAME
labels:
app: $APP_NAME
spec:
replicas: 1
selector:
matchLabels:
app: $APP_NAME
template:
metadata:
labels:
app: $APP_NAME
spec:
imagePullSecrets:
- name: my-registry-key
containers:
- name: $APP_NAME
image: $IMAGE_REPO:$IMAGE_NAME
imagePullPolicy: Always
ports:
- containerPort: 8080

View File

@@ -1,11 +0,0 @@
apiVersion: v1
kind: Service
metadata:
name: $APP_NAME
spec:
selector:
app: $APP_NAME
ports:
- protocol: TCP
port: 80
targetPort: 8080

19
pom.xml
View File

@@ -6,24 +6,7 @@
<groupId>com.example</groupId> <groupId>com.example</groupId>
<artifactId>java-maven-app</artifactId> <artifactId>java-maven-app</artifactId>
<version>1.1.5</version> <version>1.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.3.5.RELEASE</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies> <dependencies>
<dependency> <dependency>

View File

@@ -1,11 +0,0 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>MyApp</title>
</head>
<body>
<h1>Welcome to Java Maven Application</h1>
<!-- add image here <img src="" width="" /> -->
</body>
</html>

View File

@@ -1,16 +0,0 @@
import com.example.Application;
import org.junit.Test;
import static org.junit.Assert.*;
public class AppTest {
@Test
public void testApp() {
Application myApp = new Application();
String result = myApp.getStatus();
assertEquals("OK", result);
}
}

View File

@@ -1,5 +0,0 @@
#Generated by Maven
#Sat Dec 05 14:30:39 UTC 2020
version=1.1.5
groupId=com.example
artifactId=java-maven-app

View File

@@ -1,4 +0,0 @@
-------------------------------------------------------------------------------
Test set: AppTest
-------------------------------------------------------------------------------
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.126 sec

View File

@@ -1,64 +0,0 @@
<?xml version="1.0" encoding="UTF-8" ?>
<testsuite tests="1" failures="0" name="AppTest" time="0.007" errors="0" skipped="0">
<properties>
<property name="java.runtime.name" value="OpenJDK Runtime Environment"/>
<property name="sun.boot.library.path" value="/usr/local/openjdk-8/jre/lib/amd64"/>
<property name="java.vm.version" value="25.242-b08"/>
<property name="java.vm.vendor" value="Oracle Corporation"/>
<property name="maven.multiModuleProjectDirectory" value="/var/jenkins_home/workspace/java-maven-app_jenkins-jobs"/>
<property name="java.vendor.url" value="http://java.oracle.com/"/>
<property name="path.separator" value=":"/>
<property name="guice.disable.misplaced.annotation.check" value="true"/>
<property name="java.vm.name" value="OpenJDK 64-Bit Server VM"/>
<property name="file.encoding.pkg" value="sun.io"/>
<property name="sun.java.launcher" value="SUN_STANDARD"/>
<property name="sun.os.patch.level" value="unknown"/>
<property name="java.vm.specification.name" value="Java Virtual Machine Specification"/>
<property name="user.dir" value="/var/jenkins_home/workspace/java-maven-app_jenkins-jobs"/>
<property name="java.runtime.version" value="1.8.0_242-b08"/>
<property name="java.awt.graphicsenv" value="sun.awt.X11GraphicsEnvironment"/>
<property name="java.endorsed.dirs" value="/usr/local/openjdk-8/jre/lib/endorsed"/>
<property name="os.arch" value="amd64"/>
<property name="java.io.tmpdir" value="/tmp"/>
<property name="line.separator" value="
"/>
<property name="java.vm.specification.vendor" value="Oracle Corporation"/>
<property name="os.name" value="Linux"/>
<property name="classworlds.conf" value="/var/jenkins_home/tools/hudson.tasks.Maven_MavenInstallation/Maven/bin/m2.conf"/>
<property name="sun.jnu.encoding" value="UTF-8"/>
<property name="java.library.path" value="/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib"/>
<property name="maven.conf" value="/var/jenkins_home/tools/hudson.tasks.Maven_MavenInstallation/Maven/conf"/>
<property name="java.specification.name" value="Java Platform API Specification"/>
<property name="java.class.version" value="52.0"/>
<property name="sun.management.compiler" value="HotSpot 64-Bit Tiered Compilers"/>
<property name="os.version" value="5.4.0-51-generic"/>
<property name="library.jansi.path" value="/var/jenkins_home/tools/hudson.tasks.Maven_MavenInstallation/Maven/lib/jansi-native"/>
<property name="user.home" value="/var/jenkins_home"/>
<property name="user.timezone" value="Etc/UTC"/>
<property name="java.awt.printerjob" value="sun.print.PSPrinterJob"/>
<property name="java.specification.version" value="1.8"/>
<property name="file.encoding" value="UTF-8"/>
<property name="user.name" value="jenkins"/>
<property name="java.class.path" value="/var/jenkins_home/tools/hudson.tasks.Maven_MavenInstallation/Maven/boot/plexus-classworlds-2.6.0.jar"/>
<property name="java.vm.specification.version" value="1.8"/>
<property name="sun.arch.data.model" value="64"/>
<property name="java.home" value="/usr/local/openjdk-8/jre"/>
<property name="sun.java.command" value="org.codehaus.plexus.classworlds.launcher.Launcher clean package"/>
<property name="java.specification.vendor" value="Oracle Corporation"/>
<property name="user.language" value="en"/>
<property name="awt.toolkit" value="sun.awt.X11.XToolkit"/>
<property name="java.vm.info" value="mixed mode"/>
<property name="java.version" value="1.8.0_242"/>
<property name="java.ext.dirs" value="/usr/local/openjdk-8/jre/lib/ext:/usr/java/packages/lib/ext"/>
<property name="securerandom.source" value="file:/dev/./urandom"/>
<property name="sun.boot.class.path" value="/usr/local/openjdk-8/jre/lib/resources.jar:/usr/local/openjdk-8/jre/lib/rt.jar:/usr/local/openjdk-8/jre/lib/sunrsasign.jar:/usr/local/openjdk-8/jre/lib/jsse.jar:/usr/local/openjdk-8/jre/lib/jce.jar:/usr/local/openjdk-8/jre/lib/charsets.jar:/usr/local/openjdk-8/jre/lib/jfr.jar:/usr/local/openjdk-8/jre/classes"/>
<property name="java.vendor" value="Oracle Corporation"/>
<property name="maven.home" value="/var/jenkins_home/tools/hudson.tasks.Maven_MavenInstallation/Maven"/>
<property name="file.separator" value="/"/>
<property name="java.vendor.url.bug" value="http://bugreport.sun.com/bugreport/"/>
<property name="sun.cpu.endian" value="little"/>
<property name="sun.io.unicode.encoding" value="UnicodeLittle"/>
<property name="sun.cpu.isalist" value=""/>
</properties>
<testcase classname="AppTest" name="testApp" time="0.007"/>
</testsuite>