diff --git a/Jenkinsfile b/Jenkinsfile index fc93cb178..2d96355dd 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -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 ec2-user@172.31.0.38 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 ec2-user@172.31.0.38 docker rm -f nodeapp", returnStatus: true - - sh "ssh ec2-user@172.31.0.38 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 ubuntu@3.227.231.250:/home/ubuntu/" + script{ + try{ + sh "ssh ubuntu@3.227.231.250 kubectl apply -f ." + }catch(error){ + sh "ssh ubuntu@3.227.231.250 kubectl create -f ." + } + } + + } + } + } +} +}