From 5964755919849fb7b3368cb163729a2c4f850b40 Mon Sep 17 00:00:00 2001 From: Gregory Hendrickson Date: Fri, 9 Jun 2023 15:25:48 -0700 Subject: [PATCH] s --- Jenkinsfile | 106 ++++++++++++++++++++++++++-------------------------- 1 file changed, 54 insertions(+), 52 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index f201e0c..d3713f5 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,57 +1,59 @@ pipeline { - agent any - environment { - DOCKERHUB_CREDENTIALS=credentials('dockerhub-cred') - SSH_CREDENTIALS=credentials('SSH-CREDENTIALS') - } - - stages { - stage('Build') { - steps { - sh 'docker build -t aisthanestha/docker-test-image:latest .' - } - } + agent any + environment { + DOCKERHUB_CREDENTIALS=credentials('dockerhub-cred') + SSH_CREDENTIALS=credentials('SSH-CREDENTIALS') + } + + stages { + stage('Build') { + steps { + sh 'docker build -t aisthanestha/docker-test-image:latest .' + } + } - stage('Login') { - steps { - sh "echo '$DOCKERHUB_CREDENTIALS_PSW' | docker login -u '$DOCKERHUB_CREDENTIALS_USR' --password-stdin" - } - } + stage('Login') { + steps { + sh "echo '$DOCKERHUB_CREDENTIALS_PSW' | docker login -u '$DOCKERHUB_CREDENTIALS_USR' --password-stdin" + } + } - stage('Push') { - steps { - sh 'docker push aisthanestha/docker-test-image:latest' - } - } - stage('Pull and Deploy') { - steps { - node('any') { - def remote = [:] - remote.name = 'ubuntu-kc' - remote.host = '172.16.11.90' - remote.user = 'greg' - remote.password = 'Password1!' - remote.allowAnyHosts = true - // Provide a label for the Jenkins agent - writeFile file: 'run-pull-deploy.sh', text: '''docker pull aisthanestha/docker-test-image:latest && - docker stop docker-test-image && - docker rm docker-test-image && - docker run -d --name docker-test-image aisthanestha/docker-test-image:latest''' - sshScript remote: remote, script: 'run-pull-deploy.sh' - - } - } - } - - } - } - - post { - always { - node('any'){ - sh 'docker logout' - } - } - } + stage('Push') { + steps { + sh 'docker push aisthanestha/docker-test-image:latest' + } + } + + stage('Pull and Deploy') { + steps { + script { + def remote = [:] + remote.name = 'ubuntu-kc' + remote.host = '172.16.11.90' + remote.user = 'greg' + remote.password = 'Password1!' + remote.allowAnyHosts = true + + writeFile file: 'run-pull-deploy.sh', text: ''' + docker pull aisthanestha/docker-test-image:latest + docker stop docker-test-image + docker rm docker-test-image + docker run -d --name docker-test-image aisthanestha/docker-test-image:latest + ''' + + node('any') { + sshScript remote: remote, script: 'run-pull-deploy.sh' + } + } + } + } + } + post { + always { + node('any') { + sh 'docker logout' + } + } + } }