Image warm for Kubernetes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 lines
1.2KB

  1. node {
  2. checkout scm
  3. def branch = env.BRANCH_NAME
  4. def build = env.BUILD_NUMBER
  5. def image
  6. def repository = "iam21h/warm-image-operator"
  7. def image_name = "${repository}"
  8. def commit_hash = checkout(scm).GIT_COMMIT
  9. def version
  10. stage("Read version from file") {
  11. try {
  12. version = readFile file: "VERSION"
  13. echo "Detected version: ${version}"
  14. image_name = "${repository}:${version}"
  15. } catch (Exception e) {
  16. error("Failed to read version from file")
  17. }
  18. }
  19. stage("Build Image") {
  20. try {
  21. sh "docker build -t ${image_name} ."
  22. image = docker.image(image_name)
  23. } catch (Exception e) {
  24. error("Failed to build image")
  25. }
  26. }
  27. if (branch == 'master') {
  28. stage("Push Image") {
  29. try {
  30. docker.withRegistry("", "dockerhub") {
  31. image.push()
  32. }
  33. } catch(Exception e) {
  34. echo "${e}"
  35. error("Failed to push image")
  36. } finally {
  37. // cleanup
  38. sh "docker rmi ${image_name} || true"
  39. }
  40. }
  41. }
  42. }