|
| 1 | +env.name = "github-backup" |
| 2 | +env.description = "github-backup is a small tool to backup all private and public repositories from a specific GitHub organization." |
| 3 | +env.maintainer = "ops <ops@productsup.com>" |
| 4 | +env.homepage = "https://github.com/productsupcom/github-backup" |
| 5 | +String dockerImage = "golang:1.21" |
| 6 | +env.version |
| 7 | +env.branch |
| 8 | +env.gitCommitHash |
| 9 | +env.gitCommitAuthor |
| 10 | +env.gitCommitMessage |
| 11 | +env.package_file_name |
| 12 | + |
| 13 | +pipeline { |
| 14 | + agent { label 'jenkins-4'} |
| 15 | + options { |
| 16 | + buildDiscarder( |
| 17 | + logRotator( |
| 18 | + numToKeepStr: '5', |
| 19 | + artifactNumToKeepStr: '5' |
| 20 | + ) |
| 21 | + ) |
| 22 | + timestamps() |
| 23 | + timeout(time: 1, unit: 'HOURS') |
| 24 | + disableConcurrentBuilds() |
| 25 | + skipDefaultCheckout() |
| 26 | + } |
| 27 | + |
| 28 | + stages { |
| 29 | + stage("Checkout") { |
| 30 | + steps { |
| 31 | + gitCheckout() |
| 32 | + } |
| 33 | + } |
| 34 | + |
| 35 | + stage('Prepare Info') { |
| 36 | + steps { |
| 37 | + prepareInfo() |
| 38 | + } |
| 39 | + } |
| 40 | + |
| 41 | + // Pull docker image to use for the tests / build |
| 42 | + stage('Pull image') { |
| 43 | + steps { |
| 44 | + script { |
| 45 | + docker.withRegistry('https://docker.productsup.com', 'docker-registry') { |
| 46 | + sh "docker pull ${dockerImage}" |
| 47 | + } |
| 48 | + } |
| 49 | + } |
| 50 | + } |
| 51 | + |
| 52 | + stage('Run Tests') { |
| 53 | + agent { |
| 54 | + docker { |
| 55 | + image "${dockerImage}" |
| 56 | + // reuseNode is needed to make sure we got all the required information |
| 57 | + reuseNode true |
| 58 | + } |
| 59 | + } |
| 60 | + steps { |
| 61 | + sh 'go test' |
| 62 | + } |
| 63 | + } |
| 64 | + |
| 65 | + // Build go binary |
| 66 | + stage('Build go package') { |
| 67 | + agent { |
| 68 | + docker { |
| 69 | + image "${dockerImage}" |
| 70 | + // reuseNode is needed to make sure we got all the required information |
| 71 | + reuseNode true |
| 72 | + } |
| 73 | + } |
| 74 | + steps { |
| 75 | + // build and set internal variable appVersion to current version |
| 76 | + sh "go build -o ./build/${name} -ldflags \"-X main.version=${env.version}\"" |
| 77 | + } |
| 78 | + } |
| 79 | + |
| 80 | + // build production deb package when we build a tag. |
| 81 | + // we use different naming for the packages in dev and prod |
| 82 | + stage ('Build and publish prod deb package') { |
| 83 | + when { |
| 84 | + buildingTag() |
| 85 | + } |
| 86 | + steps { |
| 87 | + setPackageName(customName: "${env.name}_${env.version}") |
| 88 | + // build |
| 89 | + buildDebPackageBin( |
| 90 | + package_internal_name: "${env.name}", |
| 91 | + package_file_name: "${env.package_file_name}", |
| 92 | + version: "${env.version}", |
| 93 | + description: "${env.description}", |
| 94 | + homepage: "${env.homepage}", |
| 95 | + maintainer: "${env.maintainer}" |
| 96 | + ) |
| 97 | + // publish |
| 98 | + publishDebPackage(package_name: "${env.package_file_name}_all.deb") |
| 99 | + uploadFileToGithubRelease('productsupcom', env.name, env.TAG_NAME, "${env.name}", "build/${env.name}") |
| 100 | + } |
| 101 | + } |
| 102 | + } |
| 103 | + |
| 104 | + // Run post jobs steps |
| 105 | + post { |
| 106 | + cleanup { |
| 107 | + cleanWs deleteDirs: true |
| 108 | + } |
| 109 | + } |
| 110 | +} |
0 commit comments