Files
kiz-shop/Jenkinsfile
mindol1004 4e5ccb872f
Some checks failed
kiz-shop-pipeline/pipeline/head There was a failure building this commit
pipeline commit
2023-12-26 16:15:25 +09:00

114 lines
2.4 KiB
Groovy

pipeline {
agent any
tools {
jdk 'jdk17'
}
environment {
imagename = "mindol1004/kiz"
registryCredential = 'docker'
dockerImage = ''
}
stages {
// repository clone
stage('Repository clone') {
steps {
script {
echo 'Cloning Repository'
git url: 'http://mindol.synology.me:8418/kiz-cloud/kiz-shop.git',
branch: 'main',
credentialsId: 'Gitea'
}
}
post {
success {
echo 'Successfully Cloned Repository'
}
failure {
error 'This pipeline stops here...'
}
}
}
// gradle build
stage('Bulid Gradle') {
steps {
echo 'Bulid Gradle'
dir ('/var/jenkins_home/workspace/kiz-shop'){
sh './gradlew clean build'
}
}
post {
success {
echo 'Successfully Bulid Gradle'
}
failure {
error 'This pipeline stops here...'
}
}
}
// docker build
stage('Bulid Docker') {
steps {
echo 'Bulid Docker'
script {
dir ('/var/jenkins_home/workspace/kiz-shop'){
dockerImage = docker.build imagename
}
}
}
post {
success {
echo 'Successfully Bulid Docker'
}
failure {
error 'This pipeline stops here...'
}
}
}
// docker push
stage('Push Docker') {
steps {
echo 'Push Docker'
script {
docker.withRegistry('', registryCredential){
dockerImage.push("${env.BUILD_NUMBER}")
dockerImage.push("latest")
}
}
}
post {
success {
sh 'sudo docker rmi -f ' + imagename + ' || true'
}
failure {
error 'Docker Image Push Fail'
}
}
}
// docker run
stage('Run Docker') {
steps {
echo 'Run Docker'
script {
sh 'sudo docker stop kiz-shop || true'
sh 'sudo docker rm -f kiz-shop || true'
sh 'sudo docker run -d -p 8090:8090 --name kiz-shop ' + imagename
}
}
post {
success {
echo 'Successfully Run Docker'
}
failure {
error 'Docker Run Fail'
}
}
}
}
}