Skip to content

Commit 0767869

Browse files
authored
Merge pull request #1 from productsupcom/jenkinsfile
Add Jenkinsfile and build deb package
2 parents f442422 + f1bb100 commit 0767869

2 files changed

Lines changed: 123 additions & 0 deletions

File tree

Jenkinsfile

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
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+
}

nfpm.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
name: ""
2+
arch: "all"
3+
platform: "linux"
4+
version: "${version}"
5+
section: "utils"
6+
priority: extra
7+
maintainer: ""
8+
description: ""
9+
vendor: "Productsup"
10+
homepage: ""
11+
contents:
12+
- src: ./build/github-backup
13+
dst: /usr/bin/github-backup

0 commit comments

Comments
 (0)