Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
pipeline {
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("armanot/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: 'USERNAME', passwordVariable: 'USERPASS')]) {
script {
sh "sshpass -p '$USERPASS' -v ssh -o StrictHostKeyChecking=no $USERNAME@$prod_ip \"docker pull armanot/train-schedule:${env.BUILD_NUMBER}\""
try {
sh "sshpass -p '$USERPASS' -v ssh -o StrictHostKeyChecking=no $USERNAME@$prod_ip \"docker stop train-schedule\""
sh "sshpass -p '$USERPASS' -v ssh -o StrictHostKeyChecking=no $USERNAME@$prod_ip \"docker rm train-schedule\""
} catch (err) {
echo: 'caught error: $err'
}
sh "sshpass -p '$USERPASS' -v ssh -o StrictHostKeyChecking=no $USERNAME@$prod_ip \"docker run --restart always --name train-schedule -p 8080:8080 -d armanot/train-schedule:${env.BUILD_NUMBER}\""
}
}
}
}
}
}
30 changes: 28 additions & 2 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,31 @@ pipeline {
archiveArtifacts artifacts: 'dist/trainSchedule.zip'
}
}
}
}
stage('Build Docker Image') {
when {
branch 'master'
}
steps {
script {
app = docker.build("armanot/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")
}
}
}
}
}
}