-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
97 lines (93 loc) · 5.36 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
def vers
def outFile
def release = false
pipeline {
agent any
tools {
go 'Go 1.21'
maven 'Mvn'
}
environment {
NEXUS_CREDS = credentials('Cantara-NEXUS')
}
stages {
stage("pre") {
steps {
script {
if (env.TAG_NAME) {
vers = "${env.TAG_NAME}"
release = true
} else {
vers = "${env.GIT_COMMIT}"
}
artifactId = "nerthus2"
outFile = "${artifactId}-${vers}"
echo "New file: ${outFile}"
}
}
}
stage("test") {
steps {
script {
testApp()
}
}
}
stage("build") {
steps {
script {
echo "V: ${vers}"
echo "File: ${outFile}"
buildApp(outFile, vers)
}
}
}
stage("deploy") {
steps {
script {
echo 'deplying the application...'
echo "deploying version ${vers}"
if (release) {
sh "find . -name '${outFile}-*' -type f -exec curl -v -u "+'$NEXUS_CREDS'+" --upload-file {} https://mvnrepo.cantara.no/content/repositories/releases/no/cantara/gotools/${artifactId}/${vers}/{} \\;"
sh "cd probe && find . -name '${outFile}-*' -type f -exec curl -v -u "+'$NEXUS_CREDS'+" --upload-file {} https://mvnrepo.cantara.no/content/repositories/releases/no/cantara/gotools/${artifactId}/${vers}/probe/{} \\;"
sh "cd probe/health/cmd && find . -name '${outFile}-*' -type f -exec curl -v -u "+'$NEXUS_CREDS'+" --upload-file {} https://mvnrepo.cantara.no/content/repositories/releases/no/cantara/gotools/${artifactId}/${vers}/probe/health/{} \\;"
//sh "docker pull cantara/nerthus:${vers}"
//sh "docker image tag cantara/nerthus:${vers} cantara/nerthus:latest"
//sh "docker push cantara/nerthus:latest"
} else {
sh "find . -name '${outFile}-*' -type f -exec curl -v -u "+'$NEXUS_CREDS'+" --upload-file {} https://mvnrepo.cantara.no/content/repositories/snapshots/no/cantara/gotools/${artifactId}/${vers}/{} \\;"
sh "cd probe && find . -name '${outFile}-*' -type f -exec curl -v -u "+'$NEXUS_CREDS'+" --upload-file {} https://mvnrepo.cantara.no/content/repositories/snapshots/no/cantara/gotools/${artifactId}/${vers}/probe/{} \\;"
sh "cd probe/health/cmd && find . -name '${outFile}-*' -type f -exec curl -v -u "+'$NEXUS_CREDS'+" --upload-file {} https://mvnrepo.cantara.no/content/repositories/snapshots/no/cantara/gotools/${artifactId}/${vers}/probe/health/{} \\;"
//sh "docker pull cantara/nerthus:${vers}"
//sh "docker image tag cantara/nerthus:${vers} cantara/nerthus:snapshot-latest"
//sh "docker push cantara/nerthus:snapshot-latest"
}
sh "rm ${outFile}-*"
sh "cd probe && rm ${outFile}-*"
}
}
}
}
}
def testApp() {
echo 'testing the application...'
sh './testRecursive.sh'
}
def buildApp(outFile, vers) {
echo 'building the application...'
buildFlags = "-X 'github.com/cantara/gober/webserver/health.Version=${vers}' -X 'github.com/cantara/gober/webserver/health.BuildTime=\$(date)' -X 'github.com/cantara/gober/webserver.Name=${artifactId}' "
sh "CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags \"${buildFlags}\" -o ${outFile}-linux-amd64"
sh "CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -ldflags \"${buildFlags}\" -o ${outFile}-linux-arm64"
sh "CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -ldflags \"${buildFlags}\" -o ${outFile}-darwin-amd64"
sh "CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -ldflags \"${buildFlags}\" -o ${outFile}-darwin-arm64"
//sh "docker buildx build --platform=linux/amd64,linux/arm64 --build-arg BUILDFLAGS=\"${buildFlags}\" -t cantara/nerthus:${vers} --push ."
buildFlags = "-X 'github.com/cantara/gober/webserver/health.Version=${vers}' -X 'github.com/cantara/gober/webserver/health.BuildTime=\$(date)' -X 'github.com/cantara/gober/webserver.Name=${artifactId}-probe' "
sh "cd probe && CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags \"${buildFlags}\" -o ${outFile}-linux-amd64"
sh "cd probe && CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -ldflags \"${buildFlags}\" -o ${outFile}-linux-arm64"
sh "cd probe && CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -ldflags \"${buildFlags}\" -o ${outFile}-darwin-amd64"
sh "cd probe && CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -ldflags \"${buildFlags}\" -o ${outFile}-darwin-arm64"
sh "cd probe/health/cmd && CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o ${outFile}-linux-amd64"
sh "cd probe/health/cmd && CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -o ${outFile}-linux-arm64"
sh "cd probe/health/cmd && CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -o ${outFile}-darwin-amd64"
sh "cd probe/health/cmd && CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -o ${outFile}-darwin-arm64"
}