Skip to content

Commit

Permalink
Create docker-ci-cd
Browse files Browse the repository at this point in the history
  • Loading branch information
javahometech authored Sep 4, 2018
1 parent b5d7034 commit 80f1074
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions docker-ci-cd
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
node{
stage('Git Checkout'){
git 'https://github.com/javahometech/my-app'
}
stage('Maven Package'){
sh 'mvn clean package'
sh 'mv target/myweb*.war target/myweb.war'
}

stage('Build Docker Imager'){
sh 'docker build -t kammana/myweb:0.0.1 .'
}

stage('Push to Docker Hub'){

withCredentials([string(credentialsId: 'github-pwd', variable: 'dockerHubPwd')]) {
sh "docker login -u kammana -p ${dockerHubPwd}"
}
sh 'docker push kammana/myweb:0.0.1'
}
stage('Remove Previous Container'){
try{
def dockerRm = 'docker rm -f myweb'
sshagent(['docker-dev']) {
sh "ssh -o StrictHostKeyChecking=no [email protected] ${dockerRm}"
}
}catch(error){
// do nothing if there is an exception
}
}
stage('Deploy to Dev Environment'){
def dockerRun = 'docker run -d -p 8080:8080 --name myweb kammana/myweb:0.0.1 '
sshagent(['docker-dev']) {
sh "ssh -o StrictHostKeyChecking=no [email protected] ${dockerRun}"
}

}

}

0 comments on commit 80f1074

Please sign in to comment.