jenkinsfile 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #!groovy
  2. def GetLog(build_url) {
  3. withCredentials([string(credentialsId: 'JenkinsAPI', variable: 'token')]){
  4. def creds = 'admin:' + token
  5. def auth = creds.bytes.encodeBase64().toString()
  6. responce = httpRequest(httpMode: 'GET',
  7. url: build_url + 'consoleText',
  8. customHeaders:[[name:'Authorization', value:"Basic ${auth}"]])
  9. return responce
  10. }
  11. }
  12. def sendMessage(message){
  13. def encode = URLEncoder.encode(message,"UTF-8")
  14. withCredentials([string(credentialsId: 'TGBot', variable: 'SECRET')]) {
  15. responce = httpRequest(contentType: 'APPLICATION_JSON',
  16. httpMode: 'GET',
  17. url: "https://api.telegram.org/bot$SECRET/sendMessage?text=$encode&chat_id=-1001282104904&disable_web_page_preview=true",
  18. validResponceCodes: '200')
  19. return responce
  20. }
  21. }
  22. pipeline {
  23. agent {
  24. label 'master'
  25. }
  26. stages {
  27. stage("build project") {
  28. steps {
  29. echo 'go build main.go webPage.go'
  30. }
  31. }
  32. stage("deploy docker") {
  33. steps{
  34. echo 'docker-compose stop schedule'
  35. echo 'docker-compose up --build -d'
  36. }
  37. }
  38. }
  39. post {
  40. success {
  41. echo 'I succeeeded!'
  42. }
  43. unstable {
  44. echo 'I am unstable :/'
  45. }
  46. failure {
  47. echo 'I failed :((('
  48. sendMessage(GetLog("${BUILD_URL}"))
  49. }
  50. changed {
  51. echo 'things were different before...'
  52. }
  53. }
  54. }