From 6c0d797e270e8f3cabb94923b623187c102004f5 Mon Sep 17 00:00:00 2001 From: Gregory Hendrickson Date: Fri, 9 Jun 2023 14:35:44 -0700 Subject: [PATCH] s --- Jenkinsfile | 53 ++++++++++++++++++++--------------------------------- 1 file changed, 20 insertions(+), 33 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index a3b8624..1deab6b 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,62 +1,49 @@ -pipeline{ - +pipeline { agent any - environment { - DOCKERHUB_CREDENTIALS=credentials('dockerhub-cred') + DOCKERHUB_CREDENTIALS = credentials('dockerhub-cred') } + 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' + 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('Deploy') { - // steps { - // // Deploy to remote Docker host - // sshagent(['ssh_creds']) { - // sh "ssh -o StrictHostKeyChecking=accept-new administrator@172.16.11.90 'docker stop --name docker-test-image && docker pull aisthanestha/docker-test-image:latest && docker run -d -p 8082:80 --name docker-test-image:latest'" - // } - // } - // } - // } - stage('Pull and Deploy') - steps { - // Send commands to remote Docker host via SSH - script { - sshCommand remote: [ - credentialsId: 'SSH_CREDENTIALS', - host: '172.16.11.90', - username: '172.16.11.90' - ], command: ''' - 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 - ''' + stage('Pull and Deploy') { + steps { + script { + sshCommand remote: [ + credentialsId: 'SSH_CREDENTIALS', + host: '172.16.11.90', + username: 'administrator' + ], command: ''' + 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 + ''' + } } } - + } + post { always { sh 'docker logout' } } } -