jenkinsfile 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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(httpMode: 'GET',
  8. url: 'http://' + strip + 'consoleText',
  9. customHeaders:[[name:'Authorization', value:"Basic ${auth}"]])
  10. return responce
  11. }
  12. }
  13. pipeline {
  14. agent {
  15. label 'master'
  16. }
  17. stages {
  18. stage("build project") {
  19. steps {
  20. echo 'go build main.go webPage.go'
  21. }
  22. }
  23. stage("deploy docker") {
  24. steps{
  25. echo 'docker-compose stop schedule'
  26. echo 'docker-compose up --build -d'
  27. }
  28. }
  29. }
  30. post {
  31. success {
  32. echo 'I succeeeded!'
  33. echo GetLog("${BUILD_URL}")
  34. }
  35. unstable {
  36. echo 'I am unstable :/'
  37. }
  38. failure {
  39. echo 'I failed :((('
  40. echo GetLog("${BUILD_URL}")
  41. }
  42. changed {
  43. echo 'things were different before...'
  44. }
  45. }
  46. }