forked from vincent-huang/simple-staking
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathJenkinsfile
More file actions
123 lines (113 loc) · 4.35 KB
/
Jenkinsfile
File metadata and controls
123 lines (113 loc) · 4.35 KB
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 any
environment {
AWS_REGION = 'us-west-1'
ECR_REGISTRY = '909313268265.dkr.ecr.${AWS_REGION}.amazonaws.com'
ECR_REPOSITORY = 'tomo/babylon-staking'
HELM_RELEASE_NAME = 'babylon-staking'
HELM_CHART_DIR = 'babylon-staking'
AWS_ACCESS_KEY_ID = credentials('aws-access-key-id-tomo')
AWS_SECRET_ACCESS_KEY = credentials('aws-secret-access-key-tomo')
GIT_CREDENTIALS = 'github-supertobby-token'
GIT_BRANCH = 'main'
WEBHOOK_URL = credentials('webhook-feishu-dev')
PROJECT_DIR = '.'
NAMESPACE = 'tomo-prod'
CLUSTER_NAME = 'tomo'
}
stages {
stage('Set Image Tag') {
steps {
script {
IMAGE_TAG = sh(script: 'git rev-parse --short HEAD', returnStdout: true).trim()
DOCKER_IMAGE = "${ECR_REGISTRY}/${ECR_REPOSITORY}:${IMAGE_TAG}"
}
}
}
stage('Build Docker Image') {
steps {
script {
sh "docker build -f ${PROJECT_DIR}/Dockerfile -t ${DOCKER_IMAGE} ."
}
}
}
stage('Push to ECR') {
steps {
script {
sh """
aws ecr get-login-password --region ${AWS_REGION} | docker login --username AWS --password-stdin ${ECR_REGISTRY}
"""
sh "docker push ${DOCKER_IMAGE}"
}
}
}
stage('Deploy with Helm') {
steps {
script {
sh "aws eks update-kubeconfig --region ${AWS_REGION} --name ${CLUSTER_NAME}"
git branch: GIT_BRANCH, credentialsId: GIT_CREDENTIALS, url: 'https://github.com/NeverFadeAI/helm-charts.git'
sh "cd ${HELM_CHART_DIR}"
sh """
helm upgrade --install ${HELM_RELEASE_NAME} ./${HELM_CHART_DIR} \
--set image.tag=${IMAGE_TAG} \
--namespace ${NAMESPACE} \
--create-namespace
"""
}
}
}
}
post {
always {
script {
def buildStatus = currentBuild.currentResult
def jobName = env.JOB_NAME
def buildNumber = env.BUILD_NUMBER
def buildTime = new Date().format("yyyy-MM-dd HH:mm:ss", TimeZone.getTimeZone('UTC'))
def payload = """
{
"msg_type": "post",
"content": {
"post": {
"zh_cn": {
"title": "jenkins build ",
"content": [
[{
"tag": "text",
"text": "job: ${jobName}\\n"
},
{
"tag": "text",
"text": "status: ${buildStatus}\\n"
},
{
"tag": "text",
"text": "github branch: ${GIT_BRANCH}\\n"
},
{
"tag": "text",
"text": "time: ${buildTime}\\n"
},
{
"tag": "text",
"text": "number: ${buildNumber}\\n"
}
]
]
}
}
}
}
"""
httpRequest(
acceptType: 'APPLICATION_JSON',
contentType: 'APPLICATION_JSON',
httpMode: 'POST',
requestBody: payload,
url: WEBHOOK_URL
)
}
cleanWs()
}
}
}