jenkinsfile 1.4 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. customHeaders:[[name:'Authorization', value:"Basic ${auth}"]],
  9. contentType: 'TEXT_PLAIN')
  10. def test = responce.status
  11. }
  12. return test
  13. }
  14. def sendMessage(message){
  15. def encode = URLEncoder.encode(message,"UTF-8")
  16. withCredentials([string(credentialsId: 'TGBot', variable: 'SECRET')]) {
  17. responce = httpRequest(contentType: 'APPLICATION_JSON',
  18. httpMode: 'GET',
  19. url: "https://api.telegram.org/bot$SECRET/sendMessage?text=$encode&chat_id=-1001282104904&disable_web_page_preview=true")
  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. echo GetLog("${BUILD_URL}")
  43. }
  44. unstable {
  45. echo 'I am unstable :/'
  46. }
  47. failure {
  48. echo 'I failed :((('
  49. echo GetLog("${BUILD_URL}")
  50. }
  51. changed {
  52. echo 'things were different before...'
  53. }
  54. }
  55. }