Files
java-maven-app/Jenkinsfile
Nana Janashia 6123875bc8 add changes
2020-11-22 15:03:10 +01:00

55 lines
1.5 KiB
Groovy

#!/usr/bin/env groovy
library identifier: 'jenkins-shared-library@master', retriever: modernSCM(
[$class: 'GitSCMSource',
remote: 'https://gitlab.com/nanuchi/jenkins-shared-library.git',
credentialsId: 'gitlab-credentials'
]
)
pipeline {
agent any
tools {
maven 'Maven'
}
environment {
IMAGE_NAME = 'nanajanashia/demo-app:java-maven-2.0'
}
stages {
stage('build app') {
steps {
script {
echo 'building application jar...'
buildJar()
}
}
}
stage('build image') {
steps {
script {
echo 'building docker image...'
buildImage(env.IMAGE_NAME)
dockerLogin()
dockerPush(env.IMAGE_NAME)
}
}
}
stage('deploy') {
steps {
script {
echo 'deploying docker image to EC2...'
def shellCmd = "bash ./server-cmds.sh ${IMAGE_NAME}"
def ec2Instance = "ec2-user@35.180.251.121"
sshagent(['ec2-server-key']) {
sh "scp server-cmds.sh ${ec2Instance}:/home/ec2-user"
sh "scp docker-compose.yaml ${ec2Instance}:/home/ec2-user"
sh "ssh -o StrictHostKeyChecking=no ${ec2Instance} ${shellCmd}"
}
}
}
}
}
}