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