Jenkinsfile 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. def normalizedBranchName = "${BRANCH_NAME}".replaceAll('/','-').replaceAll('%2F','-').replaceAll('_','-').toLowerCase()
  2. def imageTag = "${normalizedBranchName}-${env.BUILD_ID}"
  3. def imageBuildId = "${env.BUILD_ID}"
  4. def dockerDeployWriteRegistry = "https://index.docker.io/v1/"
  5. def project = "abitypo3cms"
  6. def gitRepoEmail = "k.sieren@meramo.de"
  7. def imageNameWithTag = "kerstinsieren/abitypo3cms:${imageTag}"
  8. def imageNameTagLatest = "kerstinsieren/abitypo3cms:${normalizedBranchName}-latest"
  9. def helmGitRepo = "git2.meramo.org/helm_charts/abi-typo3-chart.git"
  10. pipeline {
  11. agent {
  12. kubernetes {
  13. label 'jenkins-slave'
  14. defaultContainer 'jnlp'
  15. yaml """
  16. apiVersion: v1
  17. kind: Pod
  18. spec:
  19. containers:
  20. - name: docker
  21. image: docker:1.11
  22. command:
  23. - cat
  24. tty: true
  25. volumeMounts:
  26. - name: dockersock
  27. mountPath: /var/run/docker.sock
  28. - name: tools
  29. image: argoproj/argo-cd-ci-builder:v1.0.0
  30. command:
  31. - cat
  32. tty: true
  33. volumes:
  34. - name: dockersock
  35. hostPath:
  36. path: /var/run/docker.sock
  37. """
  38. }
  39. }
  40. environment {
  41. IMAGE_REPO = "${imageNameWithTag}"
  42. }
  43. stages {
  44. stage('Build') {
  45. environment {
  46. DOCKERHUB_CREDS = credentials('deploy-docker-id')
  47. }
  48. steps {
  49. container('docker') {
  50. sh "echo ${env.GIT_COMMIT}"
  51. sh "docker build --no-cache -t ${imageNameWithTag} . && docker tag ${imageNameWithTag} ${imageNameTagLatest}"
  52. sh "docker login --username $DOCKERHUB_CREDS_USR --password $DOCKERHUB_CREDS_PSW && docker push ${imageNameWithTag} && docker push ${imageNameTagLatest}"
  53. sh "docker run --rm --entrypoint tar ${imageNameWithTag} cCj /var/www . > ${project}-${imageTag}.tar.bz2"
  54. archiveArtifacts "${project}-${imageTag}.tar.bz2"
  55. stash "${project}-${imageTag}.tar.bz2"
  56. sh "rm ${project}-${imageTag}.tar.bz2"
  57. }
  58. }
  59. }
  60. stage('Update Helm Chart') {
  61. environment {
  62. GIT_CREDS = credentials('deploy-git-id')
  63. HELM_GIT_REPO_URL = "${helmGitRepo}"
  64. GIT_REPO_EMAIL = "${gitRepoEmail}"
  65. GIT_REPO_BRANCH = "${normalizedBranchName}"
  66. }
  67. steps {
  68. container('tools') {
  69. sh "git clone https://${env.HELM_GIT_REPO_URL}"
  70. sh "git config --global user.email ${env.GIT_REPO_EMAIL}"
  71. sh "git config --global user.name ${env.GIT_CREDS_USR}"
  72. sh "wget https://github.com/mikefarah/yq/releases/download/v4.9.6/yq_linux_amd64.tar.gz"
  73. sh "tar xvf yq_linux_amd64.tar.gz"
  74. sh "mv yq_linux_amd64 /usr/bin/yq"
  75. dir("abi-typo3-chart") {
  76. withCredentials([gitUsernamePassword(credentialsId: 'deploy-git-id', gitToolName: 'git-tool')]) {
  77. sh "git checkout -b ${normalizedBranchName}"
  78. sh '''#!/bin/bash
  79. echo $GIT_REPO_EMAIL
  80. echo $GIT_COMMIT
  81. ls -lth
  82. yq eval '.image.repository = env(IMAGE_REPO)' -i values.yaml
  83. yq eval '.image.tag = env(GIT_COMMIT)' -i values.yaml
  84. cat values.yaml
  85. '''
  86. sh "git add values.yaml"
  87. sh 'git commit -m "Triggered Build '$GIT_COMMIT'"'
  88. sh "git push https://$HELM_GIT_REPO_URL --force"
  89. }
  90. }
  91. }
  92. }
  93. }
  94. }
  95. }