cleanup jenkins and add if logic.
This commit is contained in:
parent
4d5e90bc46
commit
0ad9a47221
|
@ -16,24 +16,47 @@ pipeline {
|
||||||
|
|
||||||
stage("Build Containers and push to registry") {
|
stage("Build Containers and push to registry") {
|
||||||
steps {
|
steps {
|
||||||
sh 'docker compose build --push'
|
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."
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
stage('Stop primary container') {
|
stage('Stop primary container') {
|
||||||
steps {
|
steps {
|
||||||
|
script {
|
||||||
|
if (status_p != 0) {
|
||||||
sh 'docker compose down'
|
sh 'docker compose down'
|
||||||
sh 'sleep 5'
|
sh 'sleep 5'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
stage('Start primary container') {
|
stage('Start primary container') {
|
||||||
steps {
|
steps {
|
||||||
|
script {
|
||||||
|
if (status_p != 0) {
|
||||||
sh 'docker compose down'
|
sh 'docker compose down'
|
||||||
sh 'docker compose up -d --no-color primary'
|
sh 'docker compose up -d --no-color primary'
|
||||||
sh 'docker compose ps'
|
sh 'docker compose ps'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
stage('Create contexts') {
|
stage('Create contexts') {
|
||||||
steps {
|
steps {
|
||||||
|
@ -43,17 +66,25 @@ pipeline {
|
||||||
|
|
||||||
stage('Stop secondary container') {
|
stage('Stop secondary container') {
|
||||||
steps {
|
steps {
|
||||||
|
script {
|
||||||
|
if (status_s != 0) {
|
||||||
sh 'docker --context pi502 compose down'
|
sh 'docker --context pi502 compose down'
|
||||||
sh 'sleep 5'
|
sh 'sleep 5'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
stage('Start secondary container') {
|
stage('Start secondary container') {
|
||||||
steps {
|
steps {
|
||||||
|
script {
|
||||||
|
if (status_s != 0) {
|
||||||
sh 'docker --context pi502 compose up -d --no-color secondary'
|
sh 'docker --context pi502 compose up -d --no-color secondary'
|
||||||
sh 'docker --context pi502 compose ps'
|
sh 'docker --context pi502 compose ps'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
stage('test primary dns') {
|
stage('test primary dns') {
|
||||||
steps {
|
steps {
|
||||||
|
|
Loading…
Reference in New Issue