-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathJenkinsfile_infrastructure
More file actions
105 lines (97 loc) · 5.34 KB
/
Copy pathJenkinsfile_infrastructure
File metadata and controls
105 lines (97 loc) · 5.34 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
#!groovy
node {
def homePath = pwd() + "/"
def rootPath = "/root/go/src/github.com/rancher/tfp-automation/"
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 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: 'AZURE_TFP_CLIENT_ID', variable: 'AZURE_TFP_CLIENT_ID'),
string(credentialsId: 'AZURE_TFP_CLIENT_SECRET', variable: 'AZURE_TFP_CLIENT_SECRET'),
string(credentialsId: 'AZURE_TFP_TENANT_ID', variable: 'AZURE_TFP_TENANT_ID'),
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: 'GOOGLE_TFP_EMAIL', variable: 'GOOGLE_TFP_EMAIL'),
string(credentialsId: 'GOOGLE_TFP_SERVICE_ACCOUNT', variable: 'GOOGLE_TFP_SERVICE_ACCOUNT'),
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('${AZURE_TFP_CLIENT_ID}', env.AZURE_TFP_CLIENT_ID)
config = config.replace('${AZURE_TFP_CLIENT_SECRET}', env.AZURE_TFP_CLIENT_SECRET)
config = config.replace('${AZURE_TFP_TENANT_ID}', env.AZURE_TFP_TENANT_ID)
config = config.replace('${RANCHER_LINODE_ACCESSKEY}', env.RANCHER_LINODE_ACCESSKEY)
config = config.replace('${GOOGLE_TFP_EMAIL}', env.GOOGLE_TFP_EMAIL)
config = config.replace('${GOOGLE_TFP_SERVICE_ACCOUNT}', env.GOOGLE_TFP_SERVICE_ACCOUNT)
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 "
set +x
echo "${GOOGLE_TFP_SERVICE_ACCOUNT}" | base64 -d > /tmp/gcp-key.json 2>/dev/null
set -x
gcloud auth activate-service-account ${env.GOOGLE_TFP_EMAIL} --key-file=/tmp/gcp-key.json 2>&1 &&
export GOOGLE_APPLICATION_CREDENTIALS=/tmp/gcp-key.json &&
az login --service-principal -u \"${AZURE_TFP_CLIENT_ID}\" -p \"${AZURE_TFP_CLIENT_SECRET}\" --tenant \"${AZURE_TFP_TENANT_ID}\" > /dev/null 2>&1 &&
go run ${rootPath}tests/infrastructure/main.go ${params.TEST_CASE}"
"""
} catch(err) {
echo 'Test run had failures. Collecting results...'
}
}
}
}