-
Notifications
You must be signed in to change notification settings - Fork 11
/
Jenkinsfile
123 lines (122 loc) · 4.75 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
122
123
pipeline {
agent {
docker {
image 'argo.registry:5000/epel-7-go1.19'
args '-u jenkins:jenkins'
}
}
options {
checkoutToSubdirectory('argo-messaging')
newContainerPerStage()
}
environment {
PROJECT_DIR="argo-messaging"
GH_USER = 'newgrnetci'
GH_EMAIL = '<argo@grnet.gr>'
GOPATH="${WORKSPACE}/go"
GIT_COMMIT=sh(script: "cd ${WORKSPACE}/$PROJECT_DIR && git log -1 --format=\"%H\"",returnStdout: true).trim()
GIT_COMMIT_HASH=sh(script: "cd ${WORKSPACE}/$PROJECT_DIR && git log -1 --format=\"%H\" | cut -c1-7",returnStdout: true).trim()
GIT_COMMIT_DATE=sh(script: "date -d \"\$(cd ${WORKSPACE}/$PROJECT_DIR && git show -s --format=%ci ${GIT_COMMIT_HASH})\" \"+%Y%m%d%H%M%S\"",returnStdout: true).trim()
}
stages {
stage('Build') {
steps {
echo 'Build...'
sh """
mkdir -p ${WORKSPACE}/go/src/github.com/ARGOeu
ln -sf ${WORKSPACE}/${PROJECT_DIR} ${WORKSPACE}/go/src/github.com/ARGOeu/${PROJECT_DIR}
rm -rf ${WORKSPACE}/go/src/github.com/ARGOeu/${PROJECT_DIR}/${PROJECT_DIR}
cd ${WORKSPACE}/go/src/github.com/ARGOeu/${PROJECT_DIR}
export CGO_CFLAGS"=-O2 -fstack-protector --param=ssp-buffer-size=4 -D_FORTIFY_SOURCE=2"
go build -buildmode=pie -ldflags "-s -w -linkmode=external -extldflags '-z relro -z now'"
"""
}
}
stage('Security Tests') {
steps {
sh """
cd ${WORKSPACE}/go/src/github.com/ARGOeu/${PROJECT_DIR}
/home/jenkins/checksec.py -b ./argo-messaging
"""
}
}
stage('Test') {
steps {
echo 'Test & Coverage...'
sh """
cd ${WORKSPACE}/go/src/github.com/ARGOeu/${PROJECT_DIR}
gocov test -p 1 \$(go list ./... | grep -v /vendor/) | gocov-xml > ${WORKSPACE}/coverage.xml
go test -p 1 \$(go list ./... | grep -v /vendor/) -v=1 | go-junit-report > ${WORKSPACE}/junit.xml
"""
junit '**/junit.xml'
cobertura coberturaReportFile: '**/coverage.xml'
}
}
stage('Package') {
steps {
echo 'Building Rpm...'
withCredentials(bindings: [sshUserPrivateKey(credentialsId: 'jenkins-rpm-repo', usernameVariable: 'REPOUSER', \
keyFileVariable: 'REPOKEY')]) {
sh "/home/jenkins/build-rpm.sh -w ${WORKSPACE} -b ${BRANCH_NAME} -d centos7 -p ${PROJECT_DIR} -s ${REPOKEY}"
}
archiveArtifacts artifacts: '**/*.rpm', fingerprint: true
}
post{
always {
cleanWs()
}
}
}
stage ('Deploy Docs') {
when {
branch 'devel'
}
agent {
docker {
image 'node:buster'
}
}
steps {
echo 'Publish argo-messaging docs...'
sh '''
cd $WORKSPACE/$PROJECT_DIR
cd website
npm install
'''
sshagent (credentials: ['jenkins-master']) {
sh '''
cd $WORKSPACE/$PROJECT_DIR/website
mkdir ~/.ssh && ssh-keyscan -H github.com > ~/.ssh/known_hosts
git config --global user.email ${GH_EMAIL}
git config --global user.name ${GH_USER}
GIT_USER=${GH_USER} USE_SSH=true npm run deploy
'''
}
}
}
}
post{
always {
cleanWs()
}
success {
script{
if ( env.BRANCH_NAME == 'devel' ) {
build job: '/ARGO/argodoc/devel', propagate: false
} else if ( env.BRANCH_NAME == 'master' ) {
build job: '/ARGO/argodoc/master', propagate: false
}
if ( env.BRANCH_NAME == 'master' || env.BRANCH_NAME == 'devel' ) {
slackSend( message: ":rocket: New version for <$BUILD_URL|$PROJECT_DIR>:$BRANCH_NAME Job: $JOB_NAME !")
}
}
}
failure {
script{
if ( env.BRANCH_NAME == 'master' || env.BRANCH_NAME == 'devel' ) {
slackSend( message: ":rain_cloud: Build Failed for <$BUILD_URL|$PROJECT_DIR>:$BRANCH_NAME Job: $JOB_NAME")
}
}
}
}
}