forked from Netflix/weep
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathJenkinsfile
121 lines (119 loc) · 5.31 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
import java.text.SimpleDateFormat
def FAIL_STATUS = false
def output = ""
pipeline {
agent {
kubernetes {
yamlFile '.jenkins/jenkins_runner_manifest.yaml'
}
}
stages {
stage('Git') {
steps {
container('git') {
script {
sh "git config --global --add safe.directory ${WORKSPACE}"
sh "git fetch --depth 50 --no-tags --force https://github.com/foursquare/infraeng-weep.git +refs/heads/dev:refs/remotes/origin/dev"
env.COMMIT_HASH = sh(returnStdout: true, script: "git rev-parse --short HEAD").trim()
env.FULL_COMMIT_HASH = sh(returnStdout: true, script: "git rev-parse HEAD").trim()
env.COMMIT_DATE = sh(returnStdout: true, script: "git show -s --format=%cd --date=iso HEAD").trim()
}
}
}
}
stage('gofmt') {
when {
expression {
env.CHANGE_ID
}
}
steps {
container('go') {
script {
sh "git config --global --add safe.directory ${WORKSPACE}"
sh "apt update; apt install -y python3-pip; python3 -m pip install pre-commit"
sh "go install golang.org/x/tools/cmd/goimports@latest"
catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE') {
// have to capture the exit 1 so the stage doesn't fail before the rest of the steps
def lintOut = sh(returnStdout: true, script: "cd \${WORKSPACE}; pre-commit run --all-files && echo -n \$? > \${WORKSPACE}/pre-commit.out || echo -n \$? > \${WORKSPACE}/pre-commit.out")
def lintStatus = readFile("${WORKSPACE}/pre-commit.out")
output = """Go tests build result: \n```\n${lintOut}```\n"""
if (lintStatus != "0") {
FAIL_STATUS = true
throw new Exception("Nonzero Exit. Test Failure.")
}
}
}
}
}
}
stage('xgo-build') {
when {
expression {
! env.CHANGE_ID
}
}
steps {
container('xgo') {
script {
sh "git config --global --add safe.directory ${WORKSPACE}"
// build all os targets for amd64 and arm64, output to /build
def date = new Date()
def sdf = new SimpleDateFormat("yyyy-MM-dd HH.mm.ss Z")
def buildTime = sdf.format(date).trim()
// def buildTime = "1234"
// sh "xgo -v -go 1.17 -targets='./amd64,./arm64' -out='weep' -dest='/build' -ldflags=\"-s -w -extldflags '-static' -X github.com/netflix/weep/pkg/metadata.Version=${env.BRANCH_NAME}-${env.COMMIT_HASH} -X github.com/netflix/weep/pkg/metadata.Commit=${env.COMMIT_DATE} -X github.com/netflix/weep/pkg/metadata.Date=${buildTime} \" /${WORKSPACE}; ls /build"
sh "xgo -v -go 1.17 -targets='./amd64,./arm64' -out='weep' -dest='/build' -ldflags=\"-s -w -extldflags '-static' -X 'github.com/netflix/weep/pkg/metadata.Version=foursquare_${env.BRANCH_NAME}-${env.COMMIT_HASH}' -X 'github.com/netflix/weep/pkg/metadata.Commit=${env.COMMIT_DATE}' -X 'github.com/netflix/weep/pkg/metadata.Date=${buildTime}' \" /${WORKSPACE}; ls /build"
}
}
}
}
stage('upload') {
when {
expression {
! env.CHANGE_ID
}
}
steps {
container('aws-s3') {
script {
sh "aws s3 cp --recursive /build s3://fscloud-infra-public-resources/weep/${env.BRANCH_NAME}-${env.COMMIT_HASH}/"
}
}
}
}
stage('make-latest') {
when {
branch 'release'
expression {
! env.CHANGE_ID
}
}
steps {
container('aws-s3') {
script {
sh "aws s3 cp --recursive s3://fscloud-infra-public-resources/weep/${env.BRANCH_NAME}-${env.COMMIT_HASH} s3://fscloud-infra-public-resources/weep/latest/"
sh "echo \"${env.BRANCH_NAME}\\n ${env.FULL_COMMIT_HASH}\">version.txt && aws s3 cp version.txt s3://fscloud-infra-public-resources/weep/latest/"
}
}
}
}
}
post {
always {
script {
if (FAIL_STATUS == true) {
currentBuild.result = 'FAILURE'
}
if (env.CHANGE_ID) {
if (FAIL_STATUS == true) {
output += """\n:x:"""
} else {
output += """\n:white_check_mark:"""
}
pullRequest.comment(output)
}
}
}
}
}