-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
46 lines (42 loc) · 961 Bytes
/
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
pipeline {
agent any
environment {
PRIVATEKEY=credentials('cd1436f4-0f72-48e6-b7df-43fd0f57990c')
GOROOT="/usr/local/src/go"
PATH="$GOROOT/bin:$PATH"
}
stages {
stage('Build') {
steps {
echo 'Building..'
sh 'go mod download'
sh 'GOARCH=arm GOARM=7 go build -o api main.go'
}
}
stage('Staging') {
steps {
script {
// Copy binary to EC2 using scp
sh '''
scp -i $PRIVATEKEY api \
[email protected]:~/go/bin
'''
// SSH into ec2 and setup systemd service
sh '''
ssh -i $PRIVATEKEY [email protected] \
"sudo mv ~/go/bin/api /usr/local/bin"
ssh -i $PRIVATEKEY [email protected] \
"sudo chmod +x /usr/local/bin/api"
'''
// restart the service
sh '''
ssh -i $PRIVATEKEY [email protected] \
"sudo systemctl daemon-reload"
ssh -i $PRIVATEKEY [email protected] \
"sudo systemctl restart myapi.service"
'''
}
}
}
}
}