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 1 commit into
base: master
Choose a base branch
from
Open
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
57 changes: 28 additions & 29 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,39 @@ pipeline {
agent any
environment{
DOCKER_TAG = getDockerTag()
NEXUS_URL = "172.31.34.232:8080"
IMAGE_URL_WITH_TAG = "${NEXUS_URL}/node-app:${DOCKER_TAG}"
#NEXUS_URL = "172.31.34.232:8080"
#IMAGE_URL_WITH_TAG = "${NEXUS_URL}/node-app:${DOCKER_TAG}"
}
stages{
stage('Build Docker Image'){
steps{
sh "docker build . -t ${IMAGE_URL_WITH_TAG}"
sh "docker build . -t madakala/nodeapp:${Docker_TAG}"
}
}
stage('Nexus Push'){
stage('DockerHub Push')
steps{
withCredentials([string(credentialsId: 'nexus-pwd', variable: 'nexusPwd')]) {
sh "docker login -u admin -p ${nexusPwd} ${NEXUS_URL}"
sh "docker push ${IMAGE_URL_WITH_TAG}"
}
withCredentials([string(credentialsId: 'DOCKER_HUB_CREDENTIALS', variable: 'DOCKER_HUB_CREDENTIALS')]) {
sh "docker login -u madakala -p ${DOCKER_HUB_CREDENTIALS}"
sh "docker push madakala/nodeapp:${Docker_TAG}"
}
}
}
stage('Docker Deploy Dev'){
steps{
sshagent(['tomcat-dev']) {
withCredentials([string(credentialsId: 'nexus-pwd', variable: 'nexusPwd')]) {
sh "ssh [email protected] docker login -u admin -p ${nexusPwd} ${NEXUS_URL}"
}
// Remove existing container, if container name does not exists still proceed with the build
sh script: "ssh [email protected] docker rm -f nodeapp", returnStatus: true

sh "ssh [email protected] docker run -d -p 8080:8080 --name nodeapp ${IMAGE_URL_WITH_TAG}"
}
}
}
}
}

def getDockerTag(){
def tag = sh script: 'git rev-parse HEAD', returnStdout: true
return tag
}
}
stage('Deploy to k8s')
steps{
sh "chmod +changeTag.sh"
sh "./changeTag.sh ${Docker_TAG}"
sshagent(['kops-machine']){
sh "scp -o strictHostkeyChecking=no services.yml node-app-pod.yml [email protected]:/home/ubuntu/"
script{
try{
sh "ssh [email protected] kubectl apply -f ."
}catch(error){
sh "ssh [email protected] kubectl create -f ."
}
}

}
}
}
}
}