jenkinsfile 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. return responce
  21. }
  22. }
  23. pipeline {
  24. agent {
  25. label 'master'
  26. }
  27. stages {
  28. stage("build project") {
  29. steps {
  30. echo 'go build main.go webPage.go'
  31. }
  32. }
  33. stage("deploy docker") {
  34. steps{
  35. echo 'docker-compose stop schedule'
  36. echo 'docker-compose up --build -d'
  37. }
  38. }
  39. }
  40. post {
  41. success {
  42. echo 'I succeeeded!'
  43. sendMessage("${BUILD_URL}")
  44. }
  45. unstable {
  46. echo 'I am unstable :/'
  47. }
  48. failure {
  49. echo 'I failed :((('
  50. sendMessage("${BUILD_URL}")
  51. }
  52. changed {
  53. echo 'things were different before...'
  54. }
  55. }
  56. }