-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
109 lines (104 loc) · 4.72 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
def vers
def outFile
def release = false
def choices = []
node() {
stage('prepare git tags') {
try {
sh (script: "git pull --tag")
} catch (err) {
echo err.getMessage()
}
}
stage('prepare choices') {
choices = sh (script: "git tag | git-release-helper | git-release-helper-next", returnStdout: true).trim()
}
}
pipeline {
agent any
parameters {
choice(
choices: choices,
description: 'New version',
name: 'Version'
)
}
tools {
go 'Go 1.20'
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 = sh (script: "git-release-helper-new", returnStdout: true).trim()
}
artifactId = "git-release-helper"
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 next && 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}/next/{} \\;"
sh "cd new && 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}/new/{} \\;"
} 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 next && 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}/next/{} \\;"
sh "cd new && 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}/new/{} \\;"
}
sh "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 -o ${outFile}-linux-amd64"
sh "CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -o ${outFile}-linux-arm64"
sh "CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -o ${outFile}-darwin-amd64"
sh "CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -o ${outFile}-darwin-arm64"
sh "cd next && CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o ${outFile}-linux-amd64"
sh "cd next && CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -o ${outFile}-linux-arm64"
sh "cd next && CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -o ${outFile}-darwin-amd64"
sh "cd next && CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -o ${outFile}-darwin-arm64"
sh "cd new && CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o ${outFile}-linux-amd64"
sh "cd new && CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -o ${outFile}-linux-arm64"
sh "cd new && CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -o ${outFile}-darwin-amd64"
sh "cd new && CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -o ${outFile}-darwin-arm64"
}