Jenkinsfile.renewal 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. pipeline {
  2. options {
  3. buildDiscarder logRotator(numToKeepStr: '10')
  4. disableConcurrentBuilds()
  5. timeout(time: 30, unit: 'MINUTES')
  6. }
  7. agent {
  8. label "swarm"
  9. }
  10. environment {
  11. CLUSTER_NAME='iru-swarm.infoclinica.lan'
  12. DOCKER_CERT_PATH='/run/secrets/swarm'
  13. SERVICE_NAME='proxy_letsencrypt'
  14. JENKINS_MAIL='jenkins.dev@sdsys.ru'
  15. SWARM_GIT_NAME='stack-deploy'
  16. SWARM_GIT_URL='ssh://git@git.sdsys.ru:8022/iru/stack-deploy.git'
  17. }
  18. parameters {
  19. string(
  20. name: "mailto",
  21. defaultValue: "admin@sdsys.ru",
  22. description: "Email which has to be notified."
  23. )
  24. }
  25. stages {
  26. stage("Generate Cert and Key") {
  27. steps {
  28. script {
  29. def NODE = sh (script: "DOCKER_HOST=tcp://${CLUSTER_NAME}:2376 DOCKER_TLS_VERIFY=1 docker service ps \${SERVICE_NAME} --format '{{.Node}}' --filter desired-state=Running" , returnStdout: true).trim()
  30. sh "if [ -z ${NODE} ]; then echo '${SERVICE_NAME} does not running'; exit 1; fi"
  31. def NODE_IP = sh (script: "DOCKER_HOST=tcp://${CLUSTER_NAME}:2376 DOCKER_TLS_VERIFY=1 docker node inspect ${NODE} -f '{{.Status.Addr}}'" , returnStdout: true).trim()
  32. def container_id = sh (script: "DOCKER_HOST=tcp://${NODE_IP}:2376 DOCKER_TLS_VERIFY=1 docker ps -q -f label=com.docker.swarm.service.name=\${SERVICE_NAME}" , returnStdout: true).trim()
  33. sh "DOCKER_HOST=tcp://${NODE_IP}:2376 DOCKER_TLS_VERIFY=1 docker exec -i ${container_id} /tmp/renewal.sh"
  34. }
  35. }
  36. }
  37. }
  38. post {
  39. always {
  40. echo "CleaningUp work directory"
  41. deleteDir()
  42. }
  43. success {
  44. mail charset: 'UTF-8',
  45. subject: "Jenkins build SUCCESS",
  46. mimeType: 'text/html',
  47. to: "${mailto}",
  48. body: "<b>ATTENTION!!!</b> <b><br> Jenkins job successed.\n\n <b><br>Project Name:</b> ${env.JOB_NAME} <b><br>Renewal certs and keys</b> <b><br>\nBuild Number:</b> ${env.BUILD_NUMBER} <b><br>\nURL Build:</b> ${RUN_DISPLAY_URL}"
  49. }
  50. failure {
  51. mail charset: 'UTF-8',
  52. subject: "Jenkins build ERROR",
  53. mimeType: 'text/html',
  54. to: "${mailto}",
  55. body: "<b>ATTENTION!!!</b> <b><br> Jenkins job failed.\n\n <b><br>Project Name:</b> ${env.JOB_NAME} <b><br>\nBuild Number:</b> ${env.BUILD_NUMBER} <b><br>\nURL Build:</b> ${RUN_DISPLAY_URL}"
  56. }
  57. }
  58. }