Jenkinsfile.renewal 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. NODE_NAME_LOCAL = NODE.replace(".ru", ".lan")
  32. // 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()
  33. def container_id = sh (script: "DOCKER_HOST=tcp://${NODE_NAME_LOCAL}:2376 DOCKER_TLS_VERIFY=1 docker ps -q -f label=com.docker.swarm.service.name=\${SERVICE_NAME}" , returnStdout: true).trim()
  34. sh "DOCKER_HOST=tcp://${NODE_NAME_LOCAL}:2376 DOCKER_TLS_VERIFY=1 docker exec -i ${container_id} /tmp/renewal.sh"
  35. }
  36. }
  37. }
  38. }
  39. post {
  40. always {
  41. echo "CleaningUp work directory"
  42. deleteDir()
  43. }
  44. success {
  45. mail charset: 'UTF-8',
  46. subject: "Jenkins build SUCCESS",
  47. mimeType: 'text/html',
  48. to: "${mailto}",
  49. 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}"
  50. }
  51. failure {
  52. mail charset: 'UTF-8',
  53. subject: "Jenkins build ERROR",
  54. mimeType: 'text/html',
  55. to: "${mailto}",
  56. 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}"
  57. }
  58. }
  59. }