Advertisement
PandaAcademy

Jenkinsfile_docker_compose

Oct 9th, 2023 (edited)
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1. def frontendImage="pandaacademy/frontend"
  2. def backendImage="pandaacademy/backend"
  3. def backendDockerTag=""
  4. def frontendDockerTag=""
  5. def dockerRegistry=""
  6. def registryCredentials="dockerhub"
  7.  
  8.  
  9. pipeline {
  10. agent {
  11. label 'agent'
  12. }
  13.  
  14. parameters {
  15. string(name: 'backendDockerTag', defaultValue: '', description: 'Backend docker image tag')
  16. string(name: 'frontendDockerTag', defaultValue: '', description: 'Frontend docker image tag')
  17. }
  18.  
  19. stages {
  20. stage('Adjust version') {
  21. steps {
  22. script{
  23. backendDockerTag = params.backendDockerTag.isEmpty() ? "latest" : params.backendDockerTag
  24. frontendDockerTag = params.frontendDockerTag.isEmpty() ? "latest" : params.frontendDockerTag
  25.  
  26. currentBuild.description = "Backend: ${backendDockerTag}, Frontend: ${frontendDockerTag}"
  27. }
  28. }
  29. }
  30.  
  31. stage('Clean running containers') {
  32. steps {
  33. sh "docker rm -f frontend backend"
  34. }
  35. }
  36.  
  37. stage('Deploy application') {
  38. steps {
  39. script {
  40. withEnv(["FRONTEND_IMAGE=$frontendImage:$frontendDockerTag",
  41. "BACKEND_IMAGE=$backendImage:$backendDockerTag"]) {
  42. docker.withRegistry("$dockerRegistry", "$registryCredentials") {
  43. sh 'docker-compose up -d'
  44. }
  45. }
  46. }
  47. }
  48. }
  49. }
  50.  
  51. post {
  52. always {
  53. sh "docker-compose down"
  54. cleanWs()
  55. }
  56. }
  57. }
  58.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement