how to write jenkins pipline to deploy spring boot service on docker

pipeline{

agent any

environment {
SERVICE = ‘asset-personnel-service’
}

stages{

stage(“Clone”){
steps{
echo “Cloning $SERVICE …”
git branch: ‘${BRANCH_NAME}’, credentialsId: ‘1’, url: “https://git-codecommit.us-east-2.amazonaws.com/v1/repos/$SERVICE”
}
}

stage(“Build”){
steps{
dir(‘asset-personnel-service/’) {
echo “Building $SERVICE …”
sh ‘chmod 777 gradlew’
sh ‘./gradlew build’
sh ‘./gradlew clean’
sh ‘./gradlew assemble’
}
}
}

stage(“Docker image”){
steps{
dir(‘asset-personnel-service/’) {
sh ‘sudo docker rm $(sudo docker stop $(sudo docker ps -a | grep “asset-personnel-service” | cut -d ” ” -f 1))’
sh ‘sudo docker build -t asset-personnel-service .’
sh ‘sudo docker run -it -dp 9196 asset-personnel-service’
sh ‘sudo docker ps -a | grep asset-personnel-service’

}
}
}

stage(“Backup”){
steps{
dir(‘asset-personnel-service/build/libs’) {
sh ‘sudo cp asset-personnel-service.jar /data/servers/ams_be_jars/’
}
}
}
post {
always {
cleanWs()
dir(“${env.WORKSPACE}@tmp”) {
deleteDir()
}
}
}
}

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *