jenkinsfile 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. validResponceCodes: '200')
  10. return responce
  11. }
  12. }
  13. def sendMessage(message){
  14. def encode = URLEncoder.encode(message,"UTF-8")
  15. withCredentials([string(credentialsId: 'TGBot', variable: 'SECRET')]) {
  16. responce = httpRequest(contentType: 'APPLICATION_JSON',
  17. httpMode: 'GET',
  18. url: "https://api.telegram.org/bot$SECRET/sendMessage?text=$encode&chat_id=-1001282104904&disable_web_page_preview=true",
  19. validResponceCodes: '200')
  20. def body = responce.getInputStream().getText()
  21. return body
  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. GetLog("${BUILD_URL}")
  45. }
  46. unstable {
  47. echo 'I am unstable :/'
  48. }
  49. failure {
  50. echo 'I failed :((('
  51. GetLog("${BUILD_URL}")
  52. }
  53. changed {
  54. echo 'things were different before...'
  55. }
  56. }
  57. }