148 lines
5.1 KiB
Groovy
148 lines
5.1 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 transferFileCommand_pi501 = sh(
|
|
script: "scp -r -i ${identity} -o StrictHostKeyChecking=no nrpe ${userName}@pi501.in.thelinuxpro.net:/tmp/",
|
|
returnStdout: true
|
|
).trim()
|
|
|
|
def transferFileCommand_pi502 = sh(
|
|
script: "scp -r -i ${identity} -o StrictHostKeyChecking=no nrpe ${userName}@pi502.in.thelinuxpro.net:/tmp/",
|
|
returnStdout: true
|
|
).trim()
|
|
|
|
def transferFileCommand_pi503 = sh(
|
|
script: "scp -r -i ${identity} -o StrictHostKeyChecking=no nrpe ${userName}@pi503.in.thelinuxpro.net:/tmp/",
|
|
returnStdout: true
|
|
).trim()
|
|
|
|
def transferFileCommand_pi504 = sh(
|
|
script: "scp -r -i ${identity} -o StrictHostKeyChecking=no nrpe ${userName}@pi504.in.thelinuxpro.net:/tmp/",
|
|
returnStdout: true
|
|
).trim()
|
|
|
|
echo "File Transferred to remote server: ${transferFileCommand_pi501}"
|
|
echo "File Transferred to remote server: ${transferFileCommand_pi502}"
|
|
echo "File Transferred to remote server: ${transferFileCommand_pi503}"
|
|
echo "File Transferred to remote server: ${transferFileCommand_pi504}"
|
|
|
|
def remoteCommand = "cd /tmp/nrpe ; chmod +x setup.sh; ./setup.sh"
|
|
|
|
def sshCmd_pi501 = sh(
|
|
script: "ssh -i ${identity} -o StrictHostKeyChecking=no -l ${userName} pi501.in.thelinuxpro.net 'sudo bash -c \"${remoteCommand}\"'",
|
|
returnStdout: true
|
|
).trim()
|
|
|
|
def sshCmd_pi502 = sh(
|
|
script: "ssh -i ${identity} -o StrictHostKeyChecking=no -l ${userName} pi502.in.thelinuxpro.net 'sudo bash -c \"${remoteCommand}\"'",
|
|
returnStdout: true
|
|
).trim()
|
|
|
|
def sshCmd_pi503 = sh(
|
|
script: "ssh -i ${identity} -o StrictHostKeyChecking=no -l ${userName} pi503.in.thelinuxpro.net 'sudo bash -c \"${remoteCommand}\"'",
|
|
returnStdout: true
|
|
).trim()
|
|
|
|
def sshCmd_pi504 = sh(
|
|
script: "ssh -i ${identity} -o StrictHostKeyChecking=no -l ${userName} pi504.in.thelinuxpro.net 'sudo bash -c \"${remoteCommand}\"'",
|
|
returnStdout: true
|
|
).trim()
|
|
|
|
echo "Command executed on remote server: ${sshCmd_pi501}"
|
|
echo "Command executed on remote server: ${sshCmd_pi502}"
|
|
echo "Command executed on remote server: ${sshCmd_pi503}"
|
|
echo "Command executed on remote server: ${sshCmd_pi504}"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
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'
|
|
// }
|
|
// }
|
|
}
|