-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathJenkinsfile
114 lines (99 loc) · 2.58 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
pipeline {
agent {
label 'master'
}
environment {
// HOME helps to avoid permission error
HOME = '/tmp'
NETWORK_NAME = "my-network"
SELENIUM_CLUSTER_NAME = "my-chrome"
SELENIUM_CLUSTER_URL = "http://${SELENIUM_CLUSTER_NAME}:4444/wd/hub"
TODO_APP_NAME = "todo-app"
TODO_APP_URL = "http://${TODO_APP_NAME}:8080"
}
stages {
stage('Prepare environment') {
steps {
sh "docker network create ${NETWORK_NAME}"
}
}
stage('Start Frontend') {
steps {
dir("frontend") {
sh "docker rm -f ${TODO_APP_NAME} || true"
sh "docker build --no-cache -t ${TODO_APP_NAME}:edge ."
sh "docker run --rm --name ${TODO_APP_NAME} -d --privileged --network ${NETWORK_NAME} -p 8000:8080 ${TODO_APP_NAME}:edge"
}
}
}
stage('Start Browser') {
steps {
sh "docker rm -f ${SELENIUM_CLUSTER_NAME} || true"
sh "docker run --rm --name ${SELENIUM_CLUSTER_NAME} -d --privileged --network ${NETWORK_NAME} selenium/standalone-chrome:3.141.59"
}
}
stage('Run tests') {
agent {
docker {
image 'microsoft/dotnet:2.2-sdk'
args "-p 3000:3000 --network ${NETWORK_NAME} -e ToDoApplicationUrl=${TODO_APP_URL} -e SeleniumClusterUrl=${SELENIUM_CLUSTER_URL}"
}
}
steps {
saveDotnetWorkspaceName();
sh "dotnet build && dotnet test --settings config/jenkins.runsettings --logger 'trx' --results-directory ../TestResults"
}
post {
always {
packTestResults();
}
}
}
}
post {
always {
cleanUpDockerItems();
publishAllureResults();
publishTrxResults();
cleanDotnetWorkspace();
cleanJenkinsWorkspace();
}
}
}
def DOTNET_WORKSPACE;
def saveDotnetWorkspaceName() {
script {
DOTNET_WORKSPACE = "${env.WORKSPACE}"
}
}
def cleanDotnetWorkspace() {
sh "rm -r ${DOTNET_WORKSPACE}/*"
}
def cleanJenkinsWorkspace() {
sh "rm -r ${env.WORKSPACE}/*"
}
def packTestResults() {
stash includes: 'allure-results/*', name: 'allure-results'
stash includes: 'TestResults/*', name: 'TestResults'
}
def publishAllureResults() {
unstash 'allure-results';
script {
allure([
includeProperties: false,
jdk: '',
properties: [],
reportBuildPolicy: 'ALWAYS',
results: [[path: 'allure-results']]
])
}
}
def publishTrxResults() {
unstash 'TestResults'
step([$class: 'MSTestPublisher', testResultsFile:"TestResults/*.trx", failOnError: true, keepLongStdio: true])
}
def cleanUpDockerItems() {
sh "docker rm -f ${TODO_APP_NAME} || true"
sh "docker rm -f ${SELENIUM_CLUSTER_NAME} || true"
sh "docker network rm ${NETWORK_NAME}"
}