-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
121 lines (121 loc) · 3.73 KB
/
Jenkinsfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
pipeline {
agent none
environment {
BASE_VERSION ="0.1.0"
VERSION = "${env.BASE_VERSION}${env.BRANCH_NAME == "main" ? "-SNAPSHOT" : "~${env.BRANCH_NAME}"}"
PROFILE = "${env.BRANCH_NAME == "main" ? "release" : "debug"}"
PROFILE_FLAGS = "${PROFILE == "release" ? "--release" : " "}" // Jenkins does not allow empty values.
CARGO_HOME = "/.cargo"
CARGO_TARGET_DIR = "/.cargo-target"
}
options {
timeout(time: 1, unit: "HOURS")
timestamps()
}
stages {
stage("Build & Test") {
parallel {
stage("Test") {
agent {
dockerfile {
args "-v /jenkins-cache/\${EXECUTOR_NUMBER}/cargo:${CARGO_HOME} -v /jenkins-cache/\${EXECUTOR_NUMBER}/cargo-target:${CARGO_TARGET_DIR}"
}
}
steps {
sh label: "Run tests", script: "cargo test --locked"
sh label: "Run linter", script: "cargo clippy -- --no-deps -D warnings"
sh label: "Run rustfmt", script: "scripts/check-code-format.sh"
}
post {
cleanup {
cleanWs()
}
}
}
stage("Build (Linux)") {
agent {
dockerfile {
args "-v /jenkins-cache/\${EXECUTOR_NUMBER}/cargo:${CARGO_HOME} -v /jenkins-cache/\${EXECUTOR_NUMBER}/cargo-target:${CARGO_TARGET_DIR}"
}
}
steps {
sh label: "Build ${PROFILE} binary", script: "cargo build --bins ${PROFILE_FLAGS}"
}
post {
success {
sh label: "Copy built binary", script: """
mkdir -p target/${PROFILE}
cp '${CARGO_TARGET_DIR}/${PROFILE}/pjsh' target/${PROFILE}
"""
stash(name: "linux-binary", includes: "target/${PROFILE}/pjsh")
}
cleanup {
cleanWs()
}
}
}
}
}
stage("Package (Linux)") {
agent {
label "docker"
}
steps {
unstash(name: "linux-binary")
sh label: "Build Linux packages", script: """
build/build-linux-packages.sh \
'${VERSION}' \
'${BUILD_NUMBER}' \
build/package \
'target/${PROFILE}' \
target/package
"""
sh label: "Verify Linux packages", script: "build/verify-linux-packages.sh target/package examples"
}
post {
success {
archiveArtifacts(artifacts: "target/package/*", fingerprint: true)
stash(name: "packages", includes: "target/package/*")
}
cleanup {
cleanWs()
}
}
}
stage("Deploy") {
when {
branch "main"
beforeAgent true
}
agent {
docker {
image "lgatica/openssh-client"
args "-u root:root"
}
}
steps {
unstash(name: "packages")
withCredentials([
sshUserPrivateKey(
credentialsId: "ssh-peterjonsson.se-deployer",
keyFileVariable: "SSH_KEY_FILE",
usernameVariable: "SSH_USER"
)
]) {
sh(
label: "Deploy to Debian repo",
script: """
set -euo pipefail
scp -i "\${SSH_KEY_FILE}" \
-o "BatchMode yes" -o "StrictHostKeyChecking no" -o "UserKnownHostsFile /dev/null" \
target/package/*.deb "\${SSH_USER}@peterjonsson.se:/var/www/package-repos/deb-repo/pool/main"
ssh -i "\${SSH_KEY_FILE}" \
-o "BatchMode yes" -o "StrictHostKeyChecking no" -o "UserKnownHostsFile /dev/null" \
"\${SSH_USER}@peterjonsson.se" /var/www/package-repos/refresh-deb-repo.sh
"""
)
}
}
}
}
}