-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJenkinsfile
More file actions
101 lines (96 loc) · 3.94 KB
/
Jenkinsfile
File metadata and controls
101 lines (96 loc) · 3.94 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
// Definir os seguintes parâmetros de execução nas configurações
// da pipeline: TENANCY_NAMESPACE, ENDPOINT_REGISTRY
///
pipeline{
agent any
tools{
jdk "Java21"
maven "Maven3"
}
environment {
APP_NAME = "${JOB_NAME}"
RELEASE = "v${BUILD_NUMBER}"
IMAGE_NAME = "${ENDPOINT_REGISTRY}" + "/" + "${TENANCY_NAMESPACE}" + "/" + "${APP_NAME}"
GITHUB_TOKEN = credentials('github_token_clebson')
BRANCH_NAME = "${GIT_BRANCH}".split('/').last()
REPOSITORY_NAME = "${env.GIT_URL.tokenize('/')[3].split('\\.')[0]}"
REPOSITORY_OWNER = "${env.GIT_URL.tokenize('/')[2]}"
}
stages{
stage("Cleanup Workspace"){
steps {
cleanWs()
}
}
stage("Checkout Application"){
steps {
script{
git branch: "${BRANCH_NAME}", url: "${GIT_URL}"
}
}
}
stage("Final"){
steps{
sh '''
env
'''
}
}
stage("Update Version for ArgoCD") {
steps {
script {
if(env.BRANCH_NAME == 'main'){
sh '''
cat manifests/prod/deployment.yaml
sed -i "s|$IMAGE_NAME:.*|$IMAGE_NAME:$BRANCH_NAME-$RELEASE|g" manifests/prod/deployment.yaml
cat manifests/prod/deployment.yaml
'''
}else if(env.BRANCH_NAME == 'develop'){
sh '''
cat manifests/dev/deployment.yaml
sed -i "s|novabuild:develop-.*|novabuild:develop-$RELEASE|g" manifests/dev/deployment.yaml
cat manifests/dev/deployment.yaml
'''
}else if(env.BRANCH_NAME == 'staging'){
sh '''
cat manifests/stg/deployment.yaml
sed -i "s|$IMAGE_NAME:.*|$IMAGE_NAME:$BRANCH_NAME-$RELEASE|g" manifests/stg/deployment.yaml
cat manifests/stg/deployment.yaml
'''
}
}
}
}
stage('Update Deployment File') {
steps {
script {
if(env.BRANCH_NAME == 'main'){
sh '''
git config user.email "noc@certdox.io"
git config user.name "Jenkins Agent"
git add manifests/prod/deployment.yaml
git commit -m "Update to version $RELEASE"
git push https://$GITHUB_TOKEN@github.com/$REPOSITORY_OWNER/$REPOSITORY_NAME HEAD:$BRANCH_NAME
'''
}else if(env.BRANCH_NAME == 'develop'){
sh '''
git config user.email "noc@certdox.io"
git config user.name "Jenkins Agent"
git add manifests/dev/deployment.yaml
git commit -m "Update to version $RELEASE"
git push https://$GITHUB_TOKEN@github.com/$REPOSITORY_OWNER/$REPOSITORY_NAME HEAD:$BRANCH_NAME
'''
}else if(env.BRANCH_NAME == 'staging'){
sh '''
git config user.email "noc@certdox.io"
git config user.name "Jenkins Agent"
git add manifests/stg/deployment.yaml
git commit -m "Update to version $RELEASE"
git push https://$GITHUB_TOKEN@github.com/$REPOSITORY_OWNER/$REPOSITORY_NAME HEAD:$BRANCH_NAME
'''
}
}
}
}
}
}