jenkinsfile 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #!groovy
  2. def GetLog(build_url) {
  3. def strip = build_url.replaceAll('http://','')
  4. withCredentials([string(credentialsId: 'JenkinsAPI', variable: 'token')]){
  5. def creds = 'admin:' + token
  6. def auth = creds.bytes.encodeBase64().toString()
  7. responce = httpRequest(contentType: 'APPLICATION_JSON',
  8. httpMode: 'GET',
  9. url: 'http://' + strip + 'consoleText',
  10. customHeaders:[[name:'Authorization', value:"Basic ${auth}"]])
  11. return responce
  12. }
  13. }
  14. pipeline {
  15. agent {
  16. label 'master'
  17. }
  18. stages {
  19. stage("build project") {
  20. steps {
  21. echo 'go build main.go webPage.go'
  22. }
  23. }
  24. stage("deploy docker") {
  25. steps{
  26. echo 'docker-compose stop schedule'
  27. echo 'docker-compose up --build -d'
  28. }
  29. }
  30. }
  31. post {
  32. success {
  33. echo 'I succeeeded!'
  34. echo GetLog("${BUILD_URL}")
  35. }
  36. unstable {
  37. echo 'I am unstable :/'
  38. }
  39. failure {
  40. echo 'I failed :((('
  41. echo GetLog("${BUILD_URL}")
  42. }
  43. changed {
  44. echo 'things were different before...'
  45. }
  46. }
  47. }