Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Jenkinsfile #29

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
74 changes: 63 additions & 11 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,64 @@
pipeline {
agent any
stages {
stage('Build') {
steps {
echo 'Running build automation'
sh './gradlew build --no-daemon'
archiveArtifacts artifacts: 'dist/trainSchedule.zip'
}
}
}
}
agent any
stages {
stage('Build') {
steps {
echo 'Running build automation'
sh './gradlew build --no-daemon '
archiveArtifacts artifacts: 'dist/trainSchedule.zip'
}
}
stage('Build Docker Image') {
when {
branch 'master'
}
steps {
script {
app = docker.build("syrinedkhil/train-schedule")
app.inside {
sh 'echo $(curl localhost:8080)'
}
}
}

stage('Push Docker Image') {
when {
branch 'master'
}
steps {
script {
docker.withRegistry('https://registry.hub.docker.com', 'docker_hub_login') {
app.push("${env.BUILD_NUMBER}")
app.push("latest")
}
}
}


stage('DeployToProduction') {
when {
branch 'master'
}
steps {
input 'Deploy to Production'
milestone(1)
withCredentials ([usernamePassword(credentialsId: 'webserver_login', usernameVariable: 'deploy', passwordVariable: 'jenkins')]) {
script {
sh "sshpass -p 'jenkins' -v ssh -o StrictHostKeyChecking=no deploy@prod_ip \"docker pull syrinedkhil/train-schedule:${env.BUILD_NUMBER}\""
try {
sh "sshpass -p 'jenkins' -v ssh -o StrictHostKeyChecking=no deploy@prod_ip \"docker stop train-schedule\""
sh "sshpass -p 'jenkins' -v ssh -o StrictHostKeyChecking=no deploy@prod_ip \"docker rm train-schedule\""
} catch (err) {
echo: 'caught error: $err'
}
sh "sshpass -p 'jenkins' -v ssh -o StrictHostKeyChecking=no deploy@prod_ip \"docker run --restart always --name train-schedule -p 8080:8080 -d syrinedkhil/train-schedule:${env.BUILD_NUMBER}\""
}
}
}
}



}

}