-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathJenkinsfile_vsphere
More file actions
108 lines (100 loc) · 5.03 KB
/
Copy pathJenkinsfile_vsphere
File metadata and controls
108 lines (100 loc) · 5.03 KB
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
#!groovy
node ("vsphere-vpn-1") {
def homePath = pwd() + "/"
def rootPath = "/root/go/src/github.com/rancher/tfp-automation/"
def testsDir = "github.com/rancher/tfp-automation/tests/${env.TEST_PACKAGE}"
def job_name = "${JOB_NAME}"
if (job_name.contains('/')) {
job_names = job_name.split('/')
job_name = job_names[job_names.size() - 1]
}
def testContainer = "${job_name}${env.BUILD_NUMBER}_test"
def imageName = "tfp-automation-validation-${job_name}${env.BUILD_NUMBER}"
def testResultsOut = "results.xml"
def testResultsJSON = "results.json"
def envFile = ".env"
def config = env.CONFIG
def testPackage = env.TEST_PACKAGE?.trim()
def branch = "${env.BRANCH}"
if ("${env.BRANCH}" != "null" && "${env.BRANCH}" != "") {
branch = "${env.BRANCH}"
}
def repo = scm.userRemoteConfigs
if ("${env.REPO}" != "null" && "${env.REPO}" != "") {
repo = [[url: "${env.REPO}"]]
}
def timeout = "${env.TIMEOUT}"
if ("${env.TIMEOUT}" != "null" && "${env.TIMEOUT}" != "") {
timeout = "${env.TIMEOUT}"
}
withCredentials([ string(credentialsId: 'AWS_ACCESS_KEY_ID', variable: 'AWS_ACCESS_KEY_ID'),
string(credentialsId: 'AWS_SECRET_ACCESS_KEY', variable: 'AWS_SECRET_ACCESS_KEY'),
string(credentialsId: 'RANCHER_LINODE_ACCESSKEY', variable: 'RANCHER_LINODE_ACCESSKEY'),
string(credentialsId: 'AWS_SSH_PEM_KEY', variable: 'AWS_SSH_PEM_KEY'),
string(credentialsId: 'AWS_SSH_RSA_KEY', variable: 'AWS_SSH_RSA_KEY'),
string(credentialsId: 'AWS_SSH_KEY_NAME', variable: 'AWS_SSH_KEY_NAME'),
string(credentialsId: 'RANCHER_VALID_TLS_CERT', variable: 'RANCHER_VALID_TLS_CERT'),
string(credentialsId: 'RANCHER_VALID_TLS_KEY', variable: 'RANCHER_VALID_TLS_KEY'),
string(credentialsId: 'RANCHER_VALID_TLS_CERT_NAME', variable: 'RANCHER_VALID_TLS_CERT_NAME'),
string(credentialsId: 'RANCHER_VALID_TLS_KEY_NAME', variable: 'RANCHER_VALID_TLS_KEY_NAME'),
string(credentialsId: 'QASE_AUTOMATION_TOKEN', variable: 'QASE_AUTOMATION_TOKEN')]) {
stage('Checkout') {
deleteDir()
checkout([
$class: 'GitSCM',
branches: [[name: "*/${branch}"]],
extensions: scm.extensions + [[$class: 'CleanCheckout']],
userRemoteConfigs: repo
])
}
stage('Configure and Build') {
config = config.replace('${AWS_SECRET_ACCESS_KEY}', env.AWS_SECRET_ACCESS_KEY)
config = config.replace('${AWS_ACCESS_KEY_ID}', env.AWS_ACCESS_KEY_ID)
config = config.replace('${RANCHER_LINODE_ACCESSKEY}', env.RANCHER_LINODE_ACCESSKEY)
config = config.replace('${RANCHER_VALID_TLS_CERT}', env.RANCHER_VALID_TLS_CERT)
config = config.replace('${RANCHER_VALID_TLS_KEY}', env.RANCHER_VALID_TLS_KEY)
config = config.replace('${RANCHER_VALID_TLS_CERT_NAME}', env.RANCHER_VALID_TLS_CERT_NAME)
config = config.replace('${RANCHER_VALID_TLS_KEY_NAME}', env.RANCHER_VALID_TLS_KEY_NAME)
writeFile file: 'config.yml', text: config
dir(".ssh") {
def decoded = new String(env.AWS_SSH_PEM_KEY.decodeBase64())
writeFile file: AWS_SSH_KEY_NAME, text: decoded
def decodedRsa = new String(AWS_SSH_RSA_KEY.decodeBase64())
writeFile file: JENKINS_RKE_VALIDATION, text: decodedRsa
def decodedTLSCert = new String(RANCHER_VALID_TLS_CERT.decodeBase64())
writeFile file: RANCHER_VALID_TLS_CERT_NAME, text: decodedTLSCert
def decodedTLSKey = new String(RANCHER_VALID_TLS_KEY.decodeBase64())
writeFile file: RANCHER_VALID_TLS_KEY_NAME, text: decodedTLSKey
}
env.CATTLE_TEST_CONFIG=rootPath+'config.yml'
sh "./configure.sh"
sh "./build.sh"
}
stage('Run Module Test') {
try {
sh """
docker run --name ${testContainer} -t --env-file ${envFile} ${imageName} sh -c "
/root/go/bin/gotestsum --format standard-verbose --packages=${testsDir} --junitfile ${testResultsOut} --jsonfile ${testResultsJSON} -- -timeout=${timeout} -tags=validation -v ${params.TEST_CASE};
${rootPath}pipeline/scripts/build_qase_reporter.sh;
if [ -f ${rootPath}reporter ]; then ${rootPath}reporter; fi"
"""
} catch(err) {
echo 'Test run had failures. Collecting results...'
}
}
stage('Test Report') {
sh "docker cp ${testContainer}:${rootPath}${testResultsOut} ."
step([$class: 'JUnitResultArchiver', testResults: "**/${testResultsOut}"])
sh "docker stop ${testContainer}"
sh "docker rm -v ${testContainer}"
sh "docker rmi -f ${imageName}"
if (testPackage?.toLowerCase().contains("sanity")) {
try {
slackSend(channel: "${SLACK_CHANNEL}", message: "${env.JOB_NAME} Build #${env.BUILD_NUMBER} finished. More details: ${env.BUILD_URL}")
} catch (err) {
echo "slackSend failed, will not report to channel: ${SLACK_CHANNEL}"
}
}
}
}
}