Files
docker-test-image/Jenkinsfile
Gregory Hendrickson 716f0545ed s
2023-06-09 15:30:53 -07:00

60 lines
1.7 KiB
Groovy

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 .'
}
}
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 {
script {
def remote = [:]
remote.name = 'ubuntu-kc'
remote.host = '172.16.11.90'
remote.user = "${SSH_CREDENTIALS_USR}"
remote.password = "${SSH_CREDENTIALS_PSW}"
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'
}
}
}
}