-
Notifications
You must be signed in to change notification settings - Fork 2
/
JenkinsFile.Selenium
72 lines (67 loc) · 2.32 KB
/
JenkinsFile.Selenium
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
node {
def root = pwd()
def mvn = tool 'M3'
stage("Config") {
// clone the configuration repository and copy the current configuration
def configDir = "${root}/configuration"
def configFile = "${root}/config.json"
dir(configDir) {
git url: "${env.CONFIGURATION_URL}", credentialsId: "${env.CONFIGURATION_CREDS}"
sh "mv ${configDir}/${ENVIRONMENT}-config.json ${configFile}"
deleteDir()
}
// read the current configuration
def configJson = readJSON file: "${configFile}"
for (param in configJson.credparams + configJson.jobparams) {
env."${param.name}" = (param.type == "booleanParam") ? "${param.defaultvalue}".toBoolean() : "${param.defaultvalue}"
}
}
stage('Setup') {
deleteDir()
if(env.USE_GIT_CREDS.toBoolean()) {
git url: "${env.GIT_URL}", branch: "master", credentialsId: "${env.GITLAB_CREDS}"
} else {
git url: "${env.GIT_URL}", branch: "master"
}
}
// Parameterized
def pcfSpace = "${env.SPACE}"
def pcfDomain = "${env.DOMAIN}"
def beachfrontUrl = "https://beachfront.${pcfDomain}"
def containerId = null
stage("Selenium Grid") {
dir("${root}/selenium") {
git url: "https://github.com/SeleniumHQ/docker-selenium", branch: "master"
// Check if it wasn't previously cleaned up
def existingContainerId = sh(script: """docker ps | grep \"selenium/standalone-chrome\" | awk '{print \$1}'""", returnStdout: true)
if (existingContainerId?.trim()) {
sh "docker kill ${existingContainerId}"
}
// Create instance
dir("${root}/docker-selenium/StandaloneChrome") {
containerId = sh(script: "docker run -d -p 4444:4444 -v /dev/shm:/dev/shm selenium/standalone-chrome | tail -n 1", returnStdout: true)
}
}
}
// Run the Tests
stage("Test") {
withCredentials([
[$class: 'UsernamePasswordMultiBinding', credentialsId: "${env.GX_TEST_USER}", usernameVariable: "bf_username", passwordVariable: "bf_password"]
]) {
withEnv([
"bf_url=${beachfrontUrl}",
"bf_username=${bf_username}",
"bf_password=${bf_password}"
]) {
dir("${root}/ci/Selenium") {
try {
sh "mvn clean test"
} finally {
// Cleanup
sh "docker kill ${containerId}"
}
}
}
}
}
}