jenkinsfile 1.5 KB

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