From cee1782fbe833a4c3c527592d679e3e0ac81fab0 Mon Sep 17 00:00:00 2001 From: Kameron Kenny - pi501 Date: Fri, 27 Dec 2024 10:08:57 -0500 Subject: [PATCH] jenkins --- Jenkinsfile | 85 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 Jenkinsfile diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..3414bf8 --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,85 @@ +pipeline { + 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 = sh(returnStatus: true, script: 'docker images | grep nagios | grep $(grep image docker-compose.yml | awk -F\':\' \'{ print $4 }\')') + + if (status_p != 0) { + sh 'docker compose build --push' + } else { + echo "Primary Image version already exists, no need to rebuild." + } + } + } + } + + stage('Create contexts') { + steps { + sh 'docker context ls | grep pi503 || docker context create pi503 --docker "host=ssh://pi503.in.thelinuxpro.net"' + } + } + + stage('Stop container') { + steps { + script { + def status_s = sh(returnStatus: true, script: 'grep $(docker --context pi503 compose ps | tail -n1 | awk \'{ print $2 }\') docker-compose.yml') + + if (status_s != 0) { + sh 'docker --context pi503 compose down' + sh 'sleep 5' + } else { + echo 'skip' + } + } + } + } + + stage('Start container') { + steps { + script { + def status_s = sh(returnStatus: true, script: 'grep $(docker --context pi503 compose ps | tail -n1 | awk \'{ print $2 }\') docker-compose.yml') + + if (status_s != 0) { + sh 'docker --context pi503 compose up -d' + sh 'docker --context pi503 compose ps' + } else { + echo 'skip' + } + } + } + } + +# stage('Integration Tests') { +# steps { +# sh 'mkdir -p test/results/integration' +# sh 'bats -F junit test/integration/dns/thelinux.pro/*.bat test/integration/dns/thelinux.pro/**/*.bat > test/results/integration/TEST-Integration-dns-thelinux_pro.xml' +# sh 'bats -F junit test/integration/dns/kameronkenny.com/*.bat test/integration/dns/kameronkenny.com/**/*.bat > test/results/integration/TEST-Integration-dns-kameronkenny_com.xml' +# sh 'bats -F junit test/integration/dns/in.thelinuxpro.net/*.bat test/integration/dns/in.thelinuxpro.net/**/*.bat > test/results/integration/TEST-Integration-dns-in_thelinuxpro_net.xml' +# } +# } +# } + +# post { +# always { +# archiveArtifacts artifacts: 'test/results/**/*.xml', fingerprint: true +# junit 'test/results/**/*.xml' +# sh 'rm -rf test/results' +# } +# } +#} +