diff --git a/Jenkinsfile b/Jenkinsfile index 5df2c7c..0add862 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,9 +1,4 @@ pipeline { -// environment { -// remote = [:] -// withCredentials([sshUserPrivateKey(credentialsId: 'jenkins', keyFileVariable: 'identity', usernameVariable: 'username')]) { -// remote.user = $userName - agent { label 'pi501.in.thelinuxpro.net' } @@ -23,63 +18,58 @@ pipeline { steps { script { withCredentials([sshUserPrivateKey(credentialsId: 'jenkins', keyFileVariable: 'identity', passphraseVariable: '', usernameVariable: 'userName')]) { - def remote = [:] - remote.name = "pi501.in.thelinuxpro.net" - remote.host = "pi501.in.thelinuxpro.net" - remote.allowAnyHosts = true - remote.user = $userName - remote.identityFile = $identity - sh 'echo $remote' - sh 'echo $remote.user' - sh 'echo $remote.identityFile' - sh 'echo $userName' - sh 'echo $identity' - sshPut remote: remote, from: 'nrpe', into: '/tmp' - sshCommand remote: remote, command: 'cd /tmp/nrpe/; chmod +x setup.sh; sudo ./setup.sh' - sshRemove remote: remote, path: '/tmp/nrpe' - } - } - script { - withCredentials([sshUserPrivateKey(credentialsId: 'jenkins', keyFileVariable: 'identity', passphraseVariable: '', usernameVariable: 'userName')]) { - def remote = [:] - remote.name = "pi502.in.thelinuxpro.net" - remote.host = "pi502.in.thelinuxpro.net" - remote.allowAnyHosts = true - remote.user = userName - remote.identityFile = identity + def transferFileCommand_pi501 = sh( + script: "scp -r -i ${identity} -o StrictHostKeyChecking=no nrpe ${userName}@pi501.in.thelinuxpro.net:/tmp/", + returnStdout: true + ).trim() - sshPut remote: remote, from: 'nrpe', into: '/tmp' - sshCommand remote: remote, command: 'cd /tmp/nrpe/; chmod +x setup.sh; sudo ./setup.sh' - sshRemove remote: remote, path: '/tmp/nrpe' - } - } - script { - withCredentials([sshUserPrivateKey(credentialsId: 'jenkins', keyFileVariable: 'identity', passphraseVariable: '', usernameVariable: 'userName')]) { - def remote = [:] - remote.name = "pi503.in.thelinuxpro.net" - remote.host = "pi503.in.thelinuxpro.net" - remote.allowAnyHosts = true - remote.user = userName - remote.identityFile = identity + def transferFileCommand_pi502 = sh( + script: "scp -r -i ${identity} -o StrictHostKeyChecking=no nrpe ${userName}@pi502.in.thelinuxpro.net:/tmp/", + returnStdout: true + ).trim() - sshPut remote: remote, from: 'nrpe', into: '/tmp' - sshCommand remote: remote, command: 'cd /tmp/nrpe/; chmod +x setup.sh; sudo ./setup.sh' - sshRemove remote: remote, path: '/tmp/nrpe' - } - } - script { - withCredentials([sshUserPrivateKey(credentialsId: 'jenkins', keyFileVariable: 'identity', passphraseVariable: '', usernameVariable: 'userName')]) { - def remote = [:] - remote.name = "pi504.in.thelinuxpro.net" - remote.host = "pi504.in.thelinuxpro.net" - remote.allowAnyHosts = true - remote.user = userName - remote.identityFile = identity + def transferFileCommand_pi503 = sh( + script: "scp -r -i ${identity} -o StrictHostKeyChecking=no nrpe ${userName}@pi503.in.thelinuxpro.net:/tmp/", + returnStdout: true + ).trim() - sshPut remote: remote, from: 'nrpe', into: '/tmp' - sshCommand remote: remote, command: 'cd /tmp/nrpe/; chmod +x setup.sh; sudo ./setup.sh' - sshRemove remote: remote, path: '/tmp/nrpe' + 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}" } } }