nagios/Jenkinsfile

143 lines
4.7 KiB
Groovy

pipeline {
agent {
label 'pi501.in.thelinuxpro.net'
}
stages {
stage("verify tooling") {
steps {
sh '''
docker version
docker info
docker compose version
'''
}
}
stage("Push out new nrpe configurations") {
steps {
script {
//withCredentials([sshUserPrivateKey(credentialsId: 'jenkins', keyFileVariable: 'identity', passphraseVariable: '', usernameVariable: 'userName')]) {
def remote = [:]
remote.pi501 = [:]
remote.pi502 = [:]
remote.pi503 = [:]
remote.pi504 = [:]
remote.pi501.name = "pi501.in.thelinuxpro.net"
remote.pi502.name = "pi502.in.thelinuxpro.net"
remote.pi503.name = "pi503.in.thelinuxpro.net"
remote.pi504.name = "pi504.in.thelinuxpro.net"
remote.pi501.host = "pi501.in.thelinuxpro.net"
remote.pi502.host = "pi502.in.thelinuxpro.net"
remote.pi503.host = "pi503.in.thelinuxpro.net"
remote.pi504.host = "pi504.in.thelinuxpro.net"
remote.pi501.allowAnyHosts = true
remote.pi502.allowAnyHosts = true
remote.pi503.allowAnyHosts = true
remote.pi504.allowAnyHosts = true
//remote.pi501.user = userName
//remote.pi502.user = userName
//remote.pi503.user = userName
//remote.pi504.user = userName
//remote.pi501.identityFile = identity
//remote.pi502.identityFile = identity
//remote.pi503.identityFile = identity
//remote.pi504.identityFile = identity
sshPut remote: remote.pi501, from: 'nrpe', into: '/tmp'
sshCommand remote: remote.pi501, command: 'cd /tmp/nrpe/; chmod +x setup.sh; sudo ./setup.sh'
sshRemove remote: pi501, path: '/tmp/nrpe'
sshPut remote: remote.pi502, from: 'nrpe', into: '/tmp'
sshCommand remote: remote.pi502, command: 'cd /tmp/nrpe/; chmod +x setup.sh; sudo ./setup.sh'
sshRemove remote: pi502, path: '/tmp/nrpe'
sshPut remote: remote.pi503, from: 'nrpe', into: '/tmp'
sshCommand remote: remote.pi503, command: 'cd /tmp/nrpe/; chmod +x setup.sh; sudo ./setup.sh'
sshRemove remote: pi503, path: '/tmp/nrpe'
sshPut remote: remote.pi504, from: 'nrpe', into: '/tmp'
sshCommand remote: remote.pi504, command: 'cd /tmp/nrpe/; chmod +x setup.sh; sudo ./setup.sh'
sshRemove remote: pi504, path: '/tmp/nrpe'
//}
}
}
}
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 != 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 = sh(returnStatus: true, script: 'grep $(docker --context pi503 compose ps | tail -n1 | awk \'{ print $2 }\') docker-compose.yml')
if (status != 0) {
sh 'docker --context pi503 compose down'
sh 'sleep 5'
} else {
echo 'skip'
}
}
}
}
stage('Start container') {
steps {
script {
def status = sh(returnStatus: true, script: 'grep $(docker --context pi503 compose ps | tail -n1 | awk \'{ print $2 }\') docker-compose.yml')
if (status != 0) {
sh 'docker --context pi503 compose up -d'
sh 'docker --context pi503 compose ps'
sh 'sleep 3'
sh 'docker --context pi503 compose logs'
} 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'
// }
// }
}