-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
86 lines (71 loc) · 2.77 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
pipeline {
environment {
REGISTRY = "sjc.vultrcr.com/xanny"
registryCredential = 'xanny-cr-credentials'
IMAGE_NAME = 'web-api'
}
agent any
stages {
stage('Cloning web-api Git') {
steps {
git credentialsId: 'v-tracer-web-api-jenkins-ssh', url:'[email protected]:KOCEAN33/v-tracer-web-api.git', branch: 'main'
}
}
stage('Building Docker Image') {
steps {
script {
def packageJSON = readJSON file: 'package.json'
def packageJSONVersion = packageJSON.version
env.IMAGE_VERSION = packageJSONVersion
echo "Build Image Version: ${env.IMAGE_VERSION}"
sh "docker build -t ${env.REGISTRY}/${env.IMAGE_NAME}:${env.IMAGE_VERSION} ."
}
}
}
stage('Deploying Docker Image to Container Registry') {
steps {
script {
withCredentials([[$class: 'UsernamePasswordMultiBinding', credentialsId: 'xanny-cr-credentials', usernameVariable: 'CR_USERNAME', passwordVariable: 'CR_PASSWORD']]) {
sh "docker login https://sjc.vultrcr.com/xanny -u ${CR_USERNAME} -p ${CR_PASSWORD}"
sh "docker push ${env.REGISTRY}/${env.IMAGE_NAME}:${env.IMAGE_VERSION}"
}
}
}
}
stage('Cleaning ') {
steps{
deleteDir()
}
}
stage('Git clone') {
steps{
git credentialsId: 'xanny-cluster-ssh', url:'[email protected]:KOCEAN33/xanny-cluster.git', branch: 'main'
}
}
stage('Update GitOps File') {
steps {
script {
def filename = "apps/v-tracer/environments/production/api/kustomization.yaml"
def data = readYaml file: filename
// Change Data
data.images[0].newTag = "${env.IMAGE_VERSION}"
sh "rm $filename"
writeYaml file: filename, data: data
}
}
}
stage('Push git') {
steps {
script {
sshagent (credentials: ['xanny-cluster-ssh']) {
sh"""
git add .
git commit -m "update: v-tracer-api image version ${env.IMAGE_VERSION} (jenkins automatically)"
git push origin main
"""
}
}
}
}
}
}