Skip to content

Commit

Permalink
Add Jenkinsfile and build deb package
Browse files Browse the repository at this point in the history
  • Loading branch information
azachos committed Dec 14, 2023
1 parent f442422 commit f1bb100
Show file tree
Hide file tree
Showing 2 changed files with 123 additions and 0 deletions.
110 changes: 110 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
env.name = "github-backup"
env.description = "github-backup is a small tool to backup all private and public repositories from a specific GitHub organization."
env.maintainer = "ops <[email protected]>"
env.homepage = "https://github.com/productsupcom/github-backup"
String dockerImage = "golang:1.21"
env.version
env.branch
env.gitCommitHash
env.gitCommitAuthor
env.gitCommitMessage
env.package_file_name

pipeline {
agent { label 'jenkins-4'}
options {
buildDiscarder(
logRotator(
numToKeepStr: '5',
artifactNumToKeepStr: '5'
)
)
timestamps()
timeout(time: 1, unit: 'HOURS')
disableConcurrentBuilds()
skipDefaultCheckout()
}

stages {
stage("Checkout") {
steps {
gitCheckout()
}
}

stage('Prepare Info') {
steps {
prepareInfo()
}
}

// Pull docker image to use for the tests / build
stage('Pull image') {
steps {
script {
docker.withRegistry('https://docker.productsup.com', 'docker-registry') {
sh "docker pull ${dockerImage}"
}
}
}
}

stage('Run Tests') {
agent {
docker {
image "${dockerImage}"
// reuseNode is needed to make sure we got all the required information
reuseNode true
}
}
steps {
sh 'go test'
}
}

// Build go binary
stage('Build go package') {
agent {
docker {
image "${dockerImage}"
// reuseNode is needed to make sure we got all the required information
reuseNode true
}
}
steps {
// build and set internal variable appVersion to current version
sh "go build -o ./build/${name} -ldflags \"-X main.version=${env.version}\""
}
}

// build production deb package when we build a tag.
// we use different naming for the packages in dev and prod
stage ('Build and publish prod deb package') {
when {
buildingTag()
}
steps {
setPackageName(customName: "${env.name}_${env.version}")
// build
buildDebPackageBin(
package_internal_name: "${env.name}",
package_file_name: "${env.package_file_name}",
version: "${env.version}",
description: "${env.description}",
homepage: "${env.homepage}",
maintainer: "${env.maintainer}"
)
// publish
publishDebPackage(package_name: "${env.package_file_name}_all.deb")
uploadFileToGithubRelease('productsupcom', env.name, env.TAG_NAME, "${env.name}", "build/${env.name}")
}
}
}

// Run post jobs steps
post {
cleanup {
cleanWs deleteDirs: true
}
}
}
13 changes: 13 additions & 0 deletions nfpm.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: ""
arch: "all"
platform: "linux"
version: "${version}"
section: "utils"
priority: extra
maintainer: ""
description: ""
vendor: "Productsup"
homepage: ""
contents:
- src: ./build/github-backup
dst: /usr/bin/github-backup

0 comments on commit f1bb100

Please sign in to comment.