Jenkinsfile.renewal 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. pipeline {
  2. agent {
  3. label "swarm"
  4. }
  5. environment {
  6. CLUSTER_NAME='iru-swarm.infoclinica.lan'
  7. DOCKER_CERT_PATH='/run/secrets/swarm'
  8. SERVICE_NAME='proxy_letsencrypt'
  9. JENKINS_MAIL='jenkins.dev@sdsys.ru'
  10. SWARM_GIT_NAME='stack-deploy'
  11. SWARM_GIT_URL='ssh://git@git.sdsys.ru:8022/iru/stack-deploy.git'
  12. }
  13. parameters {
  14. string(
  15. name: "mailto",
  16. defaultValue: "admin@sdsys.ru",
  17. description: "Email which has to be notified."
  18. )
  19. }
  20. stages {
  21. stage("Generate Cert and Key") {
  22. steps {
  23. script {
  24. 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()
  25. sh "if [ -z ${NODE} ]; then echo '${SERVICE_NAME} does not running'; exit 1; fi"
  26. 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()
  27. 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()
  28. sh "DOCKER_HOST=tcp://${NODE_IP}:2376 DOCKER_TLS_VERIFY=1 docker exec -i ${container_id} /tmp/renewal.sh"
  29. }
  30. }
  31. }
  32. }
  33. post {
  34. always {
  35. echo "CleaningUp work directory"
  36. deleteDir()
  37. }
  38. success {
  39. mail charset: 'UTF-8',
  40. subject: "Jenkins build SUCCESS",
  41. mimeType: 'text/html',
  42. to: "${mailto}",
  43. 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}"
  44. }
  45. failure {
  46. mail charset: 'UTF-8',
  47. subject: "Jenkins build ERROR",
  48. mimeType: 'text/html',
  49. to: "${mailto}",
  50. 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}"
  51. }
  52. }
  53. }