From 0ad9a4722142367c128a07d365c84e4630327393 Mon Sep 17 00:00:00 2001 From: Kameron Kenny <1267885+kkenny@users.noreply.github.com> Date: Wed, 15 May 2024 18:49:10 -0400 Subject: [PATCH] cleanup jenkins and add if logic. --- Jenkinsfile | 179 ++++++++++++++++++++++++++++++---------------------- 1 file changed, 105 insertions(+), 74 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 4a75c02..282fb99 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,84 +1,115 @@ pipeline { - agent { - label 'pi501.in.thelinuxpro.net' + agent { + label 'pi501.in.thelinuxpro.net' + } + + stages { + stage("verify tooling") { + steps { + sh ''' + docker version + docker info + docker compose version + ''' + } + } + + stage("Build Containers and push to registry") { + steps { + script { + def status_p = sh(returnStatus: true, script: 'docker images | grep bind9-primary | grep $(grep image docker-compose.yml | grep primary | awk -F\':\' \'{ print $4 }\')') + def status_s = sh(returnStatus: true, script: 'docker images | grep bind9-secondary | grep $(grep image docker-compose.yml | grep secondary | awk -F\':\' \'{ print $4 }\')') + + if (status_p != 0) { + sh 'docker compose build primary --push' + } else { + echo "Primary Image version already exists, no need to rebuild." + } + + if (status_s != 0) { + sh 'docker compose build secondary --push' + } else { + echo "Secondary Image version already exists, no need to rebuild." + } } + } + } - stages { - stage("verify tooling") { - steps { - sh ''' - docker version - docker info - docker compose version - ''' - } - } + stage('Stop primary container') { + steps { + script { + if (status_p != 0) { + sh 'docker compose down' + sh 'sleep 5' + } + } + } + } - stage("Build Containers and push to registry") { - steps { - sh 'docker compose build --push' - } - } + stage('Start primary container') { + steps { + script { + if (status_p != 0) { + sh 'docker compose down' + sh 'docker compose up -d --no-color primary' + sh 'docker compose ps' + } + } + } + } - stage('Stop primary container') { - steps { - sh 'docker compose down' - sh 'sleep 5' - } - } + stage('Create contexts') { + steps { + sh 'docker context ls | grep pi502 || docker context create pi502 --docker "host=ssh://pi502.in.thelinuxpro.net"' + } + } - stage('Start primary container') { - steps { - sh 'docker compose down' - sh 'docker compose up -d --no-color primary' - sh 'docker compose ps' - } - } + stage('Stop secondary container') { + steps { + script { + if (status_s != 0) { + sh 'docker --context pi502 compose down' + sh 'sleep 5' + } + } + } + } - stage('Create contexts') { - steps { - sh 'docker context ls | grep pi502 || docker context create pi502 --docker "host=ssh://pi502.in.thelinuxpro.net"' - } - } + stage('Start secondary container') { + steps { + script { + if (status_s != 0) { + sh 'docker --context pi502 compose up -d --no-color secondary' + sh 'docker --context pi502 compose ps' + } + } + } + } - stage('Stop secondary container') { - steps { - sh 'docker --context pi502 compose down' - sh 'sleep 5' - } - } + stage('test primary dns') { + steps { + sh 'dig ns1.thelinuxpro.net ANY @204.8.15.80' + sh 'dig ns1.in.thelinuxpro.net ANY @10.99.153.241' + sh 'dig ns1.thelinuxpro.net ANY @204.8.15.81' + sh 'dig ns1.in.thelinuxpro.net ANY @10.99.153.242' + sh 'dig kameronkenny.com @204.8.15.80 a' + sh 'dig kameronkenny.com @10.99.153.241 a' + sh 'dig kameronkenny.com @204.8.15.81 a' + sh 'dig kameronkenny.com @10.99.153.242 a' + } + } - stage('Start secondary container') { - steps { - sh 'docker --context pi502 compose up -d --no-color secondary' - sh 'docker --context pi502 compose ps' - } - } - - stage('test primary dns') { - steps { - sh 'dig ns1.thelinuxpro.net ANY @204.8.15.80' - sh 'dig ns1.in.thelinuxpro.net ANY @10.99.153.241' - sh 'dig ns1.thelinuxpro.net ANY @204.8.15.81' - sh 'dig ns1.in.thelinuxpro.net ANY @10.99.153.242' - sh 'dig kameronkenny.com @204.8.15.80 a' - sh 'dig kameronkenny.com @10.99.153.241 a' - sh 'dig kameronkenny.com @204.8.15.81 a' - sh 'dig kameronkenny.com @10.99.153.242 a' - } - } - - stage('verify SOA serial') { - steps { - sh 'dig +multi ns1.thelinuxpro.net ANY @204.8.15.80 soa' - sh 'dig +multi ns1.in.thelinuxpro.net ANY @10.99.153.241 soa' - sh 'dig +multi ns1.thelinuxpro.net ANY @204.8.15.81 soa' - sh 'dig +multi ns1.in.thelinuxpro.net ANY @10.99.153.242 soa' - sh 'dig +multi kameronkenny.com @204.8.15.80 soa' - sh 'dig +multi kameronkenny.com @10.99.153.241 soa' - sh 'dig +multi kameronkenny.com @204.8.15.81 soa' - sh 'dig +multi kameronkenny.com @10.99.153.242 soa' - } - } - } + stage('verify SOA serial') { + steps { + sh 'dig +multi ns1.thelinuxpro.net ANY @204.8.15.80 soa' + sh 'dig +multi ns1.in.thelinuxpro.net ANY @10.99.153.241 soa' + sh 'dig +multi ns1.thelinuxpro.net ANY @204.8.15.81 soa' + sh 'dig +multi ns1.in.thelinuxpro.net ANY @10.99.153.242 soa' + sh 'dig +multi kameronkenny.com @204.8.15.80 soa' + sh 'dig +multi kameronkenny.com @10.99.153.241 soa' + sh 'dig +multi kameronkenny.com @204.8.15.81 soa' + sh 'dig +multi kameronkenny.com @10.99.153.242 soa' + } + } + } }