forked from nixel2007/vanessa-behavior-new
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
173 lines (156 loc) · 8.18 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
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
164
165
166
167
168
169
170
171
172
173
#!groovy
properties([buildDiscarder(logRotator(artifactDaysToKeepStr: '', artifactNumToKeepStr: '3', daysToKeepStr: '', numToKeepStr: '3'))])
def tasks = [:]
//builds = ["82OF", "82UF", "836OF", "836UF", "837UF", "838UF", "839UF", "8310UF"]
builds = ["82UF", "836UF", "837UF", "838UF", "839UF", "8310UF"]
builds.each{
tasks["behavior ${it}"] = {
node ("slave") {
stage("behavior ${it}") {
//git url: 'https://github.com/silverbulleters/vanessa-behavior2.git'
checkout scm
unstash "buildResults"
bat "chcp 65001\noscript ./tools/onescript/CloseAll1CProcess.os"
bat "chcp 65001\noscript ./tools/onescript/build-service-conf.os";
try{
bat "chcp 65001\noscript ./tools/onescript/run-behavior-check-session.os ./tools/JSON/Main.json ./tools/JSON/VBParams${it}.json"
} catch (e) {
echo "behavior ${it} status : ${e}"
}
stash allowEmpty: true, includes: "build/ServiceBases/allurereport/${it}/**, build/ServiceBases/cucumber/**, build/ServiceBases/junitreport/**", name: "${it}"
}
}
}
}
firsttasks=[:]
//firsttasks["qa"] = {
node("slave"){
stage ("sonar QA"){
unix = isUnix();
checkout scm
if (env.QASONAR) {
//try{
println env.QASONAR;
def sonarcommand = "@\"./../../tools/hudson.plugins.sonar.SonarRunnerInstallation/Main_Classic/bin/sonar-scanner\""
withCredentials([[$class: 'StringBinding', credentialsId: env.SonarOAuthCredentianalID, variable: 'SonarOAuth']]) {
sonarcommand = sonarcommand + " -Dsonar.host.url=http://sonar.silverbulleters.org -Dsonar.login=${env.SonarOAuth}"
}
// Get version
def configurationText = readFile encoding: 'UTF-8', file: 'epf/vanessa-behavior/VanessaBehavior/Ext/ObjectModule.bsl'
def configurationVersion = (configurationText =~ /Версия = "(.*)";/)[0][1]
sonarcommand = sonarcommand + " -Dsonar.projectVersion=${configurationVersion}"
def makeAnalyzis = true
if (env.BRANCH_NAME == "develop") {
echo 'Analysing develop branch'
} else if (env.BRANCH_NAME.startsWith("release/")) {
sonarcommand = sonarcommand + " -Dsonar.branch=${BRANCH_NAME}"
} else if (env.BRANCH_NAME.startsWith("PR-")) {
// Report PR issues
def PRNumber = env.BRANCH_NAME.tokenize("PR-")[0]
def gitURLcommand = 'git config --local remote.origin.url'
def gitURL = ""
if (unix) {
gitURL = sh(returnStdout: true, script: gitURLcommand).trim()
} else {
gitURL = bat(returnStdout: true, script: gitURLcommand).trim()
}
def repository = gitURL.tokenize("/")[2] + "/" + gitURL.tokenize("/")[3]
repository = repository.tokenize(".")[0]
withCredentials([[$class: 'StringBinding', credentialsId: env.GithubOAuthCredentianalID, variable: 'githubOAuth']]) {
sonarcommand = sonarcommand + " -Dsonar.analysis.mode=issues -Dsonar.github.pullRequest=${PRNumber} -Dsonar.github.repository=${repository} -Dsonar.github.oauth=${env.githubOAuth}"
}
} else {
makeAnalyzis = false
}
sonarcommand = sonarcommand + " -Dsonar.scm.disabled=true"
if (makeAnalyzis) {
if (unix) {
cmd(sonarcommand, unix)
} else {
echo "${sonarcommand}"
bat "${sonarcommand}"
//cmd(sonarcommand, unix)
}
}
//} catch (e) {
// echo "sonar status : ${e}"
//}
} else {
println env.QASONAR
echo "QA runner not installed"
}
}
}
//}
firsttasks["linuxbuild"] = {
node("slavelinux"){
stage ("checkout scm") {
unix = isUnix();
if (!unix) {
command = "git config --local core.longpaths true"
cmd(command, unix);
}
//git url: 'https://github.com/silverbulleters/vanessa-behavior2.git'
checkout scm
}
stage("build"){
def unix = isUnix()
//sh 'ls -al ./build'
cmd("sudo docker pull wernight/ngrok", unix)
command = 'sudo docker run --detach -e XVFB_RESOLUTION=1920x1080x24 --volume="${PWD}":/home/ubuntu/code onec32/client:8.3.10.2466 client > /tmp/container_id_${BUILD_NUMBER}';
echo command;
cmd(command, unix);
sh 'sleep 10'
sh 'sudo docker exec -u ubuntu "$(cat /tmp/container_id_${BUILD_NUMBER})" /bin/bash -c "cd /home/ubuntu/code; DISPLAY=:1.0 sudo opm install && sudo opm update -all"'
sh 'sudo docker exec -u ubuntu "$(cat /tmp/container_id_${BUILD_NUMBER})" /bin/bash -c "cd /home/ubuntu/code; DISPLAY=:1.0 opm run init && opm run clean"'
sh 'sudo rm -f vanessa-behavior*.ospx'
sh 'sudo docker exec -u ubuntu "$(cat /tmp/container_id_${BUILD_NUMBER})" /bin/bash -c "cd /home/ubuntu/code; DISPLAY=:1.0 opm build ./"'
sh 'sudo rm -rf vanessa-behavior.tar.gz && sudo rm -f vanessa-behavior-devel.tar.gz && sudo rm -f vanessa-behavior.zip'
sh 'cd ./build; tar -czf ../vanessa-behavior.tar.gz ./vanessa-behavior.epf ./lib/ ./features/libraries ./vendor ./plugins ./locales; cd ..'
sh 'pwd && tar -czf ./vanessa-behavior-devel.tar.gz ./build env.json;'
sh 'sudo docker exec -u ubuntu "$(cat /tmp/container_id_${BUILD_NUMBER})" /bin/bash -c "cd /home/ubuntu/code; DISPLAY=:1.0 pushd ./build; zip -r ../vanessa-behavior.zip ./vanessa-behavior.epf ./lib/ ./features/libraries ./vendor ./plugins ./locales; popd"'
sh 'tar -czf ./vanessa-behavior-devel.tar.gz ./build env.json;'
sh 'sudo docker exec -u ubuntu "$(cat /tmp/container_id_${BUILD_NUMBER})" /bin/bash -c "cd /home/ubuntu/code; DISPLAY=:1.0 pushd ./build; zip -r ../vanessa-behavior.zip ./vanessa-behavior.epf ./lib/ ./features/libraries ./vendor ./plugins ./locales; popd"'
sh 'sudo docker stop "$(cat /tmp/container_id_${BUILD_NUMBER})"'
sh 'sudo docker rm "$(cat /tmp/container_id_${BUILD_NUMBER})"'
stash includes: 'build/**, *.ospx, vanessa-behavior-devel.tar.gz, vanessa-behavior.tar.gz, vanessa-behavior.zip, env.json', excludes: 'build/cache.txt', name: 'buildResults'
}
stage("archive"){
archiveArtifacts 'vanessa-behavior*.ospx,vanessa-behavior.tar.gz,vanessa-behavior-devel.tar.gz,vanessa-behavior.zip'
}
}
}
tasks["opmrunclean"] = {
node("slave"){
//git url: 'https://github.com/silverbulleters/vanessa-behavior2.git'
checkout scm
bat "opm run clean"
}
}
parallel firsttasks
parallel tasks
tasks = [:]
tasks["report"] = {
node {
stage("report"){
unstash 'buildResults'
builds.each{
unstash "${it}"
}
try{
allure commandline: 'allure2', includeProperties: false, jdk: '', results: [[path: 'build/ServiceBases/allurereport/']]
} catch (e) {
echo "behavior status : ${e}"
}
junit 'build/ServiceBases/junitreport/*.xml'
cucumber fileIncludePattern: '**/*.json', jsonReportDirectory: 'build/ServiceBases/cucumber'
}
}
}
//tasks["sonar"] = {
//}
parallel tasks
def cmd(command, isunix) {
// TODO при запуске Jenkins не в режиме UTF-8 нужно написать chcp 1251 вместо chcp 65001
if (isunix) { sh "${command}" } else {bat "chcp 65001\n${command}"}
}