-
Notifications
You must be signed in to change notification settings - Fork 1
/
Jenkinsfile.bak
164 lines (159 loc) · 5.07 KB
/
Jenkinsfile.bak
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
@Library('msales-jenkins-libraries@PL1-1291') _
pipeline {
//agent { label "optimizer-ui" }
agent any
options {
buildDiscarder(logRotator(artifactDaysToKeepStr: '', artifactNumToKeepStr: '', daysToKeepStr: '', numToKeepStr: '5'))
}
environment {
// SLACK_WEBHOOK_URL = "https://hooks.slack.com/services/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"
JIRA_PROJECT = "BLT"
GIT_COMMITS_LOG = "/tmp/bamboo-integration-git-commits.log"
}
stages {
stage('Checkout') {
steps {
// slackNotification('STARTED', 'msales', 'optimizer-ui', env.BRANCH_NAME, SLACK_WEBHOOK_URL)
sh 'env'
script {
if (env.BRANCH_NAME == 'master') {
// notify deployment slack channel
// slackNotification('STARTED', 'msales', 'optimizer-ui', env.BRANCH_NAME, "https://hooks.slack.com/services/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")
def git_tag_old = sh(returnStdout: true, script: 'git describe --tags --abbrev=0 HEAD^').trim()
sh("git log ${git_tag_old}..HEAD --oneline | grep -Eo '([A-Z0-9]{3,}-)([0-9]+)' | sort -u > /tmp/bamboo-integration-git-commits.log")
} else if (env.BRANCH_NAME == 'hotfix') {
// notify deployment slack channel
// slackNotification('STARTED', 'msales', 'optimizer-ui', env.BRANCH_NAME, "https://hooks.slack.com/services/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")
def git_tag_old = sh(returnStdout: true, script: 'git describe --tags --abbrev=0 HEAD^').trim()
def git_log = sh("git log ${git_tag_old}..HEAD --oneline | grep -Eo '([A-Z0-9]{3,}-)([0-9]+)' | sort -u")
env.DEPLOY_STAGING = 'No'
} else if (env.BRANCH_NAME.startsWith('PR-')) {
env.DEPLOY_STAGING = 'No'
} else {
env.DEPLOY_STAGING = input message: 'Deploy to STAGING ?', ok: 'Confirm', parameters: [choice(name: 'DEPLOY_STAGING', choices: 'Yes\nNo')]
}
}
}
}
stage('JIRA') {
when {
anyOf {
branch 'master';
branch 'hotfix'
}
}
steps {
script {
env.GIT_TAG = sh(returnStdout: true, script: 'git describe --tags').trim()
def git_log = readFile('/tmp/bamboo-integration-git-commits.log')
def jira_version = jiraVersion("BLT ${env.GIT_TAG}", JIRA_PROJECT, "create")
jiraTicketsFromLog(git_log, jira_version)
}
}
}
stage('Build') {
steps {
echo "Build Step"
}
}
stage('Tests') {
steps {
parallel (
"behat": {
echo "Behat tests..."
sh "sleep 2"
},
"phpunit": {
echo "PHPUnit tests..."
sh "sleep 2"
}
)
}
}
stage('Build clean-up') {
steps {
echo "Build clean-up..."
}
}
stage('Deploy: Staging') {
when {
anyOf {
branch 'master';
environment name: 'DEPLOY_STAGING', value: 'Yes'
}
}
steps {
script {
def BUILD_NO = BUILD_ID as Integer
def PREVIOUS_BUILD = BUILD_NO - 1
def ansible_hosts = ["server01", "server02", "server03", "server04"]
def builders = [:]
ansible_hosts.each() {
stage -> builders[stage] = {
echo "Deoploying..."
sh "sleep 2"
}
}
parallel builders
}
}
}
stage('Deploy: Production') {
when {
anyOf {
branch 'master';
branch 'hotfix'
}
}
steps {
script {
input id: 'Deploy_production', message: 'Deploy to PRODUCTION ?'
def BUILD_NO = BUILD_ID as Integer
def PREVIOUS_BUILD = BUILD_NO - 1
def ansible_hosts = ["server01", "server02", "server03", "server04"]
def builders = [:]
ansible_hosts.each() {
stage -> builders[stage] = {
echo "Deoploying..."
sh "sleep 2"
}
}
parallel builders
}
}
}
stage('Merging branches') {
when {
anyOf {
branch 'master';
branch 'hotfix'
}
}
steps {
echo "Mergin branches..."
script {
try {
sh 'uname -a | grep -i linux'
} catch (err) {
echo "Caught: ${err}"
//slackSend channel: '#jenkins_test', color: 'danger', message: "Failed to merge branch: ${env.BRANCH_NAME}"
//currentBuild.result = 'FAILURE'
}
}
}
}
}
post {
always {
cleanWs notFailBuild: true
}
success {
// slackNotification('SUCCESSFUL', 'msales', 'optimizer-ui', env.BRANCH_NAME, SLACK_WEBHOOK_URL)
// notify deployment slack channel
// slackNotification('SUCCESSFUL', 'msales', 'optimizer-ui', env.BRANCH_NAME, "https://hooks.slack.com/services/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")
script {
def jira_version = jiraVersion("BLT ${env.GIT_TAG}", JIRA_PROJECT, "released")
}
}
}
}