-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathJenkinsfile
124 lines (119 loc) · 4.08 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
pipeline {
agent { label 'small' }
environment {
imagename = "ghcr.io/pilotdataplatform/dataops"
imagename_staging = "ghcr.io/pilotdataplatform/dataops"
commit = sh(returnStdout: true, script: 'git describe --always').trim()
registryCredential = 'pilot-ghcr'
dockerImage = ''
}
stages {
stage('Git clone for dev') {
when {branch "develop"}
steps{
script {
git branch: "develop",
url: 'https://github.com/PilotDataPlatform/dataops.git',
credentialsId: 'lzhao'
}
}
}
/** it will be handled by github actions
stage('DEV: Run unit tests') {
when { branch 'develop' }
steps {
withCredentials([
usernamePassword(credentialsId: 'readonly', usernameVariable: 'PIP_USERNAME', passwordVariable: 'PIP_PASSWORD'),
string(credentialsId:'VAULT_TOKEN', variable: 'VAULT_TOKEN'),
string(credentialsId:'VAULT_URL', variable: 'VAULT_URL'),
file(credentialsId:'VAULT_CRT', variable: 'VAULT_CRT')
]) {
sh """
pip install --user poetry==1.1.12
${HOME}/.local/bin/poetry config virtualenvs.in-project true
${HOME}/.local/bin/poetry config http-basic.pilot ${PIP_USERNAME} ${PIP_PASSWORD}
${HOME}/.local/bin/poetry install --no-root --no-interaction
${HOME}/.local/bin/poetry run pytest --verbose -c tests/pytest.ini
"""
}
}
}
**/
stage('DEV Build and push image') {
when {branch "develop"}
steps{
script {
docker.withRegistry('https://ghcr.io', registryCredential) {
customImage = docker.build('$imagename:alembic-$commit-CAC', '--target alembic-image .')
customImage.push()
}
docker.withRegistry('https://ghcr.io', registryCredential) {
customImage = docker.build('$imagename:dataops-$commit-CAC', '--target dataops-image .')
customImage.push()
}
}
}
}
stage('DEV Remove image') {
when {branch "develop"}
steps{
sh 'docker rmi $imagename:alembic-$commit-CAC'
sh 'docker rmi $imagename:dataops-$commit-CAC'
}
}
stage('DEV Deploy') {
when {branch "develop"}
steps{
build(job: "/VRE-IaC/UpdateAppVersion", parameters: [
[$class: 'StringParameterValue', name: 'TF_TARGET_ENV', value: 'dev' ],
[$class: 'StringParameterValue', name: 'TARGET_RELEASE', value: 'dataops-utility' ],
[$class: 'StringParameterValue', name: 'NEW_APP_VERSION', value: "$commit" ]
])
}
}
/**
stage('Git clone staging') {
when {branch "main"}
steps{
script {
git branch: "main",
url: 'https://github.com/PilotDataPlatform/dataops.git',
credentialsId: 'lzhao'
}
}
}
stage('STAGING Building and push image') {
when {branch "main"}
steps{
script {
docker.withRegistry('https://ghcr.io', registryCredential) {
customImage = docker.build("$imagename_staging:${env.commit}", ".")
customImage.push()
}
}
}
}
stage('STAGING Remove image') {
when {branch "main"}
steps{
sh "docker rmi $imagename_staging:$commit"
}
}
stage('STAGING Deploy') {
when {branch "main"}
steps{
build(job: "/VRE-IaC/Staging-UpdateAppVersion", parameters: [
[$class: 'StringParameterValue', name: 'TF_TARGET_ENV', value: 'staging' ],
[$class: 'StringParameterValue', name: 'TARGET_RELEASE', value: 'dataops-utility' ],
[$class: 'StringParameterValue', name: 'NEW_APP_VERSION', value: "$commit" ]
])
}
}
**/
}
post {
failure {
slackSend color: '#FF0000', message: "Build Failed! - ${env.JOB_NAME} ${env.commit} (<${env.BUILD_URL}|Open>)", channel: 'jenkins-dev-staging-monitor'
}
}
}