Compare commits
6 Commits
complete-p
...
deploy-on-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
31ae1c5153 | ||
|
|
b128506eec | ||
|
|
0a40971e52 | ||
|
|
ba11b6ecc8 | ||
|
|
127fe8818c | ||
|
|
322a9fb1b9 |
45
Jenkinsfile
vendored
45
Jenkinsfile
vendored
@@ -2,33 +2,11 @@
|
|||||||
|
|
||||||
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') {
|
|
||||||
steps {
|
|
||||||
script {
|
|
||||||
echo 'incrementing app version...'
|
|
||||||
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 app') {
|
||||||
steps {
|
steps {
|
||||||
script {
|
script {
|
||||||
echo "building the application..."
|
echo "building the application..."
|
||||||
sh 'mvn clean package'
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -36,11 +14,6 @@ pipeline {
|
|||||||
steps {
|
steps {
|
||||||
script {
|
script {
|
||||||
echo "building the docker image..."
|
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}"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -48,27 +21,11 @@ pipeline {
|
|||||||
environment {
|
environment {
|
||||||
AWS_ACCESS_KEY_ID = credentials('jenkins_aws_access_key_id')
|
AWS_ACCESS_KEY_ID = credentials('jenkins_aws_access_key_id')
|
||||||
AWS_SECRET_ACCESS_KEY = credentials('jenkins_aws_secret_access_key')
|
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 docker image...'
|
||||||
sh 'envsubst < kubernetes/deployment.yaml | kubectl apply -f -'
|
sh 'kubectl create deployment nginx-deployment --image=nginx'
|
||||||
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'
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
apiVersion: v1
|
|
||||||
kind: Service
|
|
||||||
metadata:
|
|
||||||
name: $APP_NAME
|
|
||||||
spec:
|
|
||||||
selector:
|
|
||||||
app: $APP_NAME
|
|
||||||
ports:
|
|
||||||
- protocol: TCP
|
|
||||||
port: 80
|
|
||||||
targetPort: 8080
|
|
||||||
2
pom.xml
2
pom.xml
@@ -6,7 +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.1.4</version>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<plugins>
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
#Generated by Maven
|
#Generated by Maven
|
||||||
#Sat Dec 05 14:30:39 UTC 2020
|
#Sun Nov 29 08:01:35 UTC 2020
|
||||||
version=1.1.5
|
version=1.1.4
|
||||||
groupId=com.example
|
groupId=com.example
|
||||||
artifactId=java-maven-app
|
artifactId=java-maven-app
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
Test set: AppTest
|
Test set: AppTest
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.126 sec
|
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.096 sec
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" ?>
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
<testsuite tests="1" failures="0" name="AppTest" time="0.007" errors="0" skipped="0">
|
<testsuite tests="1" failures="0" name="AppTest" time="0.01" errors="0" skipped="0">
|
||||||
<properties>
|
<properties>
|
||||||
<property name="java.runtime.name" value="OpenJDK Runtime Environment"/>
|
<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="sun.boot.library.path" value="/usr/local/openjdk-8/jre/lib/amd64"/>
|
||||||
@@ -60,5 +60,5 @@
|
|||||||
<property name="sun.io.unicode.encoding" value="UnicodeLittle"/>
|
<property name="sun.io.unicode.encoding" value="UnicodeLittle"/>
|
||||||
<property name="sun.cpu.isalist" value=""/>
|
<property name="sun.cpu.isalist" value=""/>
|
||||||
</properties>
|
</properties>
|
||||||
<testcase classname="AppTest" name="testApp" time="0.007"/>
|
<testcase classname="AppTest" name="testApp" time="0.01"/>
|
||||||
</testsuite>
|
</testsuite>
|
||||||
Reference in New Issue
Block a user