-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
186 lines (178 loc) · 7.48 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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
pipeline {
options {
gitLabConnection("gitlab just-ai")
buildDiscarder(logRotator(numToKeepStr: '10', artifactNumToKeepStr: '10'))
disableConcurrentBuilds()
timeout(time: 60, unit: 'MINUTES')
timestamps()
}
agent {
label 'caila-dev-cloud-agent'
}
parameters {
string(name: "BRANCH", defaultValue: "dev", description: "")
booleanParam(name: 'NEED_REBUILD', defaultValue: false, description: '')
booleanParam(name: 'RUN_TESTS', defaultValue: true, description: '')
}
stages {
stage('Prepare') {
steps {
script {
RESULT_BRANCH = env.gitlabBranch != null ? env.gitlabBranch : params.BRANCH
manager.addShortText("${RESULT_BRANCH}")
echo "${env.gitlabBranch}"
}
git url: "git@gitlab.just-ai.com:mpl-public/mpl-python-sdk.git",
branch: "${RESULT_BRANCH}",
credentialsId: 'bitbucket_key'
}
}
stage('Update spec') {
steps {
script {
updateGitlabCommitStatus name: STAGE_NAME, state: "running"
sh("./mlp-specs/update.sh")
def hasChanges = !sh(returnStdout: true, script: 'git status -s mlp-specs').trim().isEmpty()
env.NEED_REBUILD = hasChanges
}
}
}
stage('Rebuild client stubs') {
when {
expression { env.NEED_REBUILD == 'true' || params.NEED_REBUILD }
}
steps {
updateGitlabCommitStatus name: STAGE_NAME, state: "running"
sh "./generate-protobuf.sh"
sh "./generate-api-client.sh"
sh "echo `docker images --digests | grep openapitools/openapi-generator-cli`"
sh "git add mlp_api"
sh "git commit -m 'Automatic update API spec from CI' mlp-specs mlp_api mlp_sdk/grpc"
sh "git push"
}
}
stage('Lint') {
steps {
updateGitlabCommitStatus name: STAGE_NAME, state: "running"
withPythonEnv('/opt/ansible-venv-python3/bin/python') {
sh "/opt/ansible-venv-python3/bin/pip install ruff==0.6.4"
sh "ruff check --config pyproject.toml ."
}
}
}
stage('Tests') {
when {
expression { params.RUN_TESTS ?: false || env.NEED_REBUILD == 'true' }
}
environment {
NEXUS_CREDS = credentials('jenkins-for-pypi')
S3_SECRET_KEY = credentials('rnd_s3_secret_key')
S3_STORAGE_CONFIG = """{
"mlp_bucket": "rnd-models",
"service_name": "s3",
"region": "ru-1a",
"access_key": "72116_rnd-models-user",
"secret_key": "${S3_SECRET_KEY}",
"endpoint": "https://248305.selcdn.ru",
"data_dir": "Z8ht8D1YNM/rnd-models"
}"""
}
steps {
script {
updateGitlabCommitStatus name: STAGE_NAME, state: "running"
sh "sh ./run_mlp_tests.sh"
}
}
}
stage('Rebuild MLP Services') {
when {
expression { RESULT_BRANCH in ['dev','stable','release'] }
}
steps {
parallel (
// "build mlp-aimyvoice-base-service" : {
// build job: "mlp-aimyvoice-base-service-build/${RESULT_BRANCH}", wait: false
// },
"build mlp_task_zoo" : {
build job: "mlp_task_zoo-build/${RESULT_BRANCH}", wait: false
},
"build sd" : {
build job: "sd-build/${RESULT_BRANCH}", wait: false
}
)
}
}
stage('Merge release to stable') {
when {
expression {
RESULT_BRANCH == 'release'
}
}
steps {
sshagent(credentials: ['bitbucket_key']) {
sh "git config user.email 'jenkins@just-ai.com'"
sh "git config user.name 'Jenkins'"
sh """git checkout stable --force"""
sh """git pull origin stable"""
sh """git merge --no-commit --no-ff origin/release || true"""
sh """git reset -- mlp_api"""
sh """git commit -m 'Automatic merge from release to stable' || true"""
sh """git push"""
}
}
}
stage('Merge stable to dev') {
when {
expression {
RESULT_BRANCH == 'stable'
}
}
steps {
sshagent(credentials: ['bitbucket_key']) {
sh "git config user.email 'jenkins@just-ai.com'"
sh "git config user.name 'Jenkins'"
sh """git checkout dev --force"""
sh """git pull origin dev"""
sh """git merge --no-commit --no-ff origin/stable || true"""
sh """git reset -- mlp_api"""
sh """git commit -m 'Automatic merge from stable to dev' || true"""
sh """git push"""
}
}
}
}
post {
failure {
updateGitlabCommitStatus name: "Prepare", state: "failed"
updateGitlabCommitStatus name: "Update spec", state: "failed"
updateGitlabCommitStatus name: "Rebuild client stubs", state: "failed"
updateGitlabCommitStatus name: "Lint", state: "failed"
updateGitlabCommitStatus name: "Tests", state: "failed"
updateGitlabCommitStatus name: "Rebuild MLP Services", state: "failed"
}
success {
updateGitlabCommitStatus name: "Prepare", state: "success"
updateGitlabCommitStatus name: "Update spec", state: "success"
updateGitlabCommitStatus name: "Rebuild client stubs", state: "success"
updateGitlabCommitStatus name: "Lint", state: "success"
updateGitlabCommitStatus name: "Tests", state: "success"
updateGitlabCommitStatus name: "Rebuild MLP Services", state: "success"
}
unstable {
updateGitlabCommitStatus name: "Prepare", state: "failed"
updateGitlabCommitStatus name: "Update spec", state: "failed"
updateGitlabCommitStatus name: "Rebuild client stubs", state: "failed"
updateGitlabCommitStatus name: "Lint", state: "failed"
updateGitlabCommitStatus name: "Tests", state: "failed"
updateGitlabCommitStatus name: "Rebuild MLP Services", state: "failed"
}
aborted {
updateGitlabCommitStatus name: "Prepare", state: "canceled"
updateGitlabCommitStatus name: "Update spec", state: "canceled"
updateGitlabCommitStatus name: "Rebuild client stubs", state: "canceled"
updateGitlabCommitStatus name: "Lint", state: "canceled"
updateGitlabCommitStatus name: "Tests", state: "canceled"
updateGitlabCommitStatus name: "Rebuild MLP Services", state: "canceled"
}
}
}