Utilitaires pour la création de pipeline Jenkins dans l’environnement Cadoles.
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.

129 lines
3.8KB

  1. def buildPackageWithCPKG(
  2. String packageProfile = "debian",
  3. String packageArch = "",
  4. String packageBranch = "",
  5. String baseImage = "",
  6. String destDir = "./packages",
  7. Boolean forceRebuild = false
  8. ) {
  9. def builds = []
  10. // Retrieve commit tags
  11. def commitTags = sh(script: 'git describe --exact-match --abbrev=0', returnStdout: true).split(' ')
  12. if (commitTags.length == 0) {
  13. error 'No build build tags on last commit'
  14. }
  15. // For each tags
  16. for (tag in commitTags) {
  17. // Split tag to retrieve context informations
  18. def tagParts = tag.split('/')
  19. def packageEnv = tagParts[1]
  20. def packageDistrib = tagParts[2]
  21. def packageVersion = tagParts[3]
  22. // Create .tamarinrc file
  23. def tamarinrc = """
  24. project_version=${packageVersion}
  25. no_version_suffix=${ packageEnv == 'stable' || packageEnv == 'staging' ? 'yes' : 'no' }
  26. """.stripIndent()
  27. writeFile file: '.tamarinrc', text: tamarinrc
  28. sh "rm -rf ${destDir}/*"
  29. stage("Build ${packageEnv} package (version ${packageVersion}) for ${packageDistrib}") {
  30. def result = [:]
  31. result.put('tag', tag)
  32. result.put('env', packageEnv)
  33. result.put('version', packageVersion)
  34. result.put('distrib', packageDistrib)
  35. def packages = buildPackage(packageProfile, packageArch, baseImage, destDir, forceRebuild)
  36. result.put('packages', packages)
  37. builds << result
  38. }
  39. }
  40. return builds
  41. }
  42. def buildPackage(
  43. String packageProfile = "debian",
  44. String packageArch = "",
  45. String baseImage = "",
  46. String destDir = "./packages",
  47. Boolean forceRebuild = false
  48. ) {
  49. def tamarinImage
  50. def packages = []
  51. stage("Create Tamarin environment") {
  52. tamarinImage = buildDockerImage()
  53. }
  54. stage("Run Tamarin") {
  55. def dockerArgs = """
  56. -v /var/run/docker.sock:/var/run/docker.sock
  57. ${forceRebuild ? '-e TAMARIN_FORCE_REBUILD=1' : ''}
  58. ${packageArch ? '-e TAMARIN_PACKAGE_ARCH='+packageArch : ''}
  59. ${baseImage ? '-e TAMARIN_BASE_IMAGE='+baseImage : ''}
  60. ${packageProfile ? '-e TAMARIN_PROFILE='+packageProfile : ''}
  61. -e TAMARIN_DEST_DIR=${destDir}
  62. """.stripIndent()
  63. tamarinImage.inside(dockerArgs) {
  64. sh 'run-tamarin'
  65. }
  66. packages = sh(script: "find '${destDir}' -name '*.deb' -type f", returnStdout: true)
  67. .split('\n')
  68. .collect { return it.trim() }
  69. .findAll { it != '' }
  70. }
  71. return packages
  72. }
  73. def prepareEnvironment(
  74. String packageProfile = "debian",
  75. String baseImage = ""
  76. ) {
  77. def tamarinImage
  78. stage("Create Tamarin environment") {
  79. tamarinImage = buildDockerImage()
  80. }
  81. stage("Prepare Tamarin") {
  82. def dockerArgs = """
  83. -v /var/run/docker.sock:/var/run/docker.sock
  84. ${baseImage ? '-e TAMARIN_BASE_IMAGE='+baseImage : ''}
  85. ${packageProfile ? '-e TAMARIN_PROFILE='+packageProfile : ''}
  86. -e TAMARIN_PREPARE_ONLY=true
  87. -e TAMARIN_FORCE_REBUILD=true
  88. """.stripIndent()
  89. tamarinImage.inside(dockerArgs) {
  90. sh 'run-tamarin'
  91. }
  92. }
  93. }
  94. def buildDockerImage() {
  95. dir ('.tamarin') {
  96. def dockerfile = libraryResource 'com/cadoles/tamarin/Dockerfile'
  97. writeFile file:'Dockerfile', text:dockerfile
  98. def runTamarinScript = libraryResource 'com/cadoles/tamarin/run-tamarin.sh'
  99. writeFile file:'run-tamarin.sh', text:runTamarinScript
  100. def safeJobName = URLDecoder.decode(env.JOB_NAME).toLowerCase().replace('/', '-').replace(' ', '-')
  101. def imageTag = "${safeJobName}-${env.BUILD_ID}"
  102. return docker.build("tamarin:${imageTag}", ".")
  103. }
  104. }