-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
122 lines (114 loc) · 4.83 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
def CODE_VERSION = ''
def IS_IMAGE_BUILDED = false
def isSuccess
def vers
def SEM_VERSION = ''
pipeline {
agent {
label 'stage'
}
environment {
GITHUB_TOKEN = credentials('GH_TOKEN')
}
options {
skipDefaultCheckout true
disableConcurrentBuilds()
}
stages {
stage('Checkout') {
steps {
checkout([
$class: 'GitSCM',
branches: scm.branches,
extensions: scm.extensions + [[$class: 'LocalBranch'], [$class: 'WipeWorkspace']],
userRemoteConfigs: [[credentialsId: 'StreetcodeGithubCreds', url: 'git@github.com:ita-social-projects/StreetCode_FrontendServer.git']],
doGenerateSubmoduleConfigurations: scm.doGenerateSubmoduleConfigurations
])
}
}
stage('Print details') {
steps {
echo "BUILD_ID..............${env.BUILD_ID}"
echo "BUILD_NUMBER..........${env.BUILD_NUMBER}"
echo "BUILD_TAG.............${env.BUILD_TAG}"
echo "EXECUTOR_NUMBER.......${env.EXECUTOR_NUMBER}"
echo "JOB_NAME..............${env.JOB_NAME}"
echo "NODE_NAME.............${env.NODE_NAME}"
echo "WORKSPACE.............${env.WORKSPACE}"
}
}
stage('Setup dependencies') {
steps {
script {
sh 'dotnet tool update --global GitVersion.Tool --version 5.12.0'
}
}
}
stage('Build') {
steps {
script {
sh(script: 'dotnet gitversion > GITVERSION_PROPERTIES', returnStdout: true)
sh "cat GITVERSION_PROPERTIES"
sh(script: "dotnet gitversion | grep -oP '(?<=\"MajorMinorPatch\": \")[^\"]*' > version", returnStatus: true)
sh "cat version"
vers = readFile(file: 'version').trim()
sh "echo ${vers}"
env.CODE_VERSION = readFile(file: 'version').trim()
echo "${env.CODE_VERSION}"
SEM_VERSION="${env.CODE_VERSION}"
sh "npm version ${env.CODE_VERSION} --allow-same-version --no-git-tag-version"
env.CODE_VERSION = "${env.CODE_VERSION}.${env.BUILD_NUMBER}"
echo "${env.CODE_VERSION}"
def gitCommit = sh(returnStdout: true, script: 'git log -1 --pretty=%B | cat').trim()
currentBuild.displayName = "${env.CODE_VERSION}-${BRANCH_NAME}:${gitCommit}"
}
}
}
stage('Build image') {
when {
branch pattern: "release/[0-9].[0-9].[0-9]", comparator: "REGEXP"
}
steps {
script {
withCredentials([usernamePassword(credentialsId: 'docker-login-streetcode', passwordVariable: 'password', usernameVariable: 'username')]){
sh "docker build -t ${username}/streetcode-frontend-server:latest ."
IS_IMAGE_BUILDED = true
}
}
}
}
stage('Push image') {
when {
expression { IS_IMAGE_BUILDED == true }
}
steps {
script {
withCredentials([usernamePassword(credentialsId: 'docker-login-streetcode', passwordVariable: 'password', usernameVariable: 'username')]){
sh 'echo "${password}" | docker login -u "${username}" --password-stdin'
sh "docker push ${username}/streetcode-frontend-server:latest"
sh "docker tag ${username}/streetcode-frontend-server:latest ${username}/streetcode-frontend-server:${env.CODE_VERSION}"
sh "docker push ${username}/streetcode-frontend-server:${env.CODE_VERSION}"
IS_IMAGE_PUSH = true
}
}
}
}
stage('Merge release') {
when {
expression { IS_IMAGE_PUSH == true }
}
steps {
input message: 'Do you want to merge release branch ?', ok: 'Yes', submitter: 'admin_1, ira_zavushchak , dev'
script {
sh 'echo ${BRANCH_NAME}'
sh "git checkout master"
sh 'echo ${BRANCH_NAME}'
sh "git merge release/${env.SEM_VERSION}"
sh "npm version ${env.CODE_VERSION} -m 'Upgrade to %s as part of release'"
sh "git push origin main"
}
}
}
}
}
}