Librairie utilitaire pour Jenkins
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.

tamarin.groovy 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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 buildDockerImage() {
  74. dir ('.tamarin') {
  75. def dockerfile = libraryResource 'com/cadoles/tamarin/Dockerfile'
  76. writeFile file:'Dockerfile', text:dockerfile
  77. def runTamarinScript = libraryResource 'com/cadoles/tamarin/run-tamarin.sh'
  78. writeFile file:'run-tamarin.sh', text:runTamarinScript
  79. def safeJobName = URLDecoder.decode(env.JOB_NAME).toLowerCase().replace('/', '-').replace(' ', '-')
  80. def imageTag = "${safeJobName}-${env.BUILD_ID}"
  81. return docker.build("tamarin:${imageTag}", ".")
  82. }
  83. }