-
Notifications
You must be signed in to change notification settings - Fork 542
Expand file tree
/
Copy pathJenkinsfile
More file actions
166 lines (156 loc) · 5.88 KB
/
Jenkinsfile
File metadata and controls
166 lines (156 loc) · 5.88 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
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
@Library('pipeline-utils')
import com.snowflake.DevEnvUtils
import groovy.json.JsonOutput
timestamps {
node('parallelizable-c7') {
stage('checkout') {
scmInfo = checkout scm
println("${scmInfo}")
env.GIT_BRANCH = scmInfo.GIT_BRANCH
env.GIT_COMMIT = scmInfo.GIT_COMMIT
}
stage('Authenticate Artifactory') {
script {
new DevEnvUtils().withSfCli {
sh "sf artifact oci auth"
}
}
}
stage('Build') {
withCredentials([
usernamePassword(credentialsId: '063fc85b-62a6-4181-9d72-873b43488411', usernameVariable: 'AWS_ACCESS_KEY_ID', passwordVariable: 'AWS_SECRET_ACCESS_KEY')
]) {
sh '''\
|cd $WORKSPACE
|export GIT_BRANCH=${GIT_BRANCH}
|export GIT_COMMIT=${GIT_COMMIT}
|./ci/build_docker.sh
|cp dist/**/*.txt dist/repaired_wheels/
|cp dist/*.tar.gz dist/repaired_wheels/
|aws s3 cp --only-show-errors ./dist/repaired_wheels/ s3://sfc-eng-jenkins/repository/python_connector/linux/${GIT_BRANCH}/${GIT_COMMIT}/ --recursive --include '*'
|echo ${GIT_COMMIT} > latest_commit
|aws s3 cp --only-show-errors latest_commit s3://sfc-eng-jenkins/repository/python_connector/linux/${GIT_BRANCH}/
'''.stripMargin()
}
}
params = [
string(name: 'branch', value: 'main'),
string(name: 'client_git_commit', value: scmInfo.GIT_COMMIT),
string(name: 'client_git_branch', value: scmInfo.GIT_BRANCH),
string(name: 'parent_job', value: env.JOB_NAME),
string(name: 'parent_build_number', value: env.BUILD_NUMBER),
string(name: 'USE_PASSWORD', value: 'true')
]
parallel(
'Test': {
stage('Test') {
parallel (
'Test Python 39': { build job: 'RT-PyConnector39-PC',parameters: params},
'Test Python 310': { build job: 'RT-PyConnector310-PC',parameters: params},
'Test Python 311': { build job: 'RT-PyConnector311-PC',parameters: params},
'Test Python 312': { build job: 'RT-PyConnector312-PC',parameters: params},
'Test Python 313': { build job: 'RT-PyConnector313-PC',parameters: params},
'Test Python 314': { build job: 'RT-PyConnector314-PC',parameters: params},
'Test Python 39 OldDriver': { build job: 'RT-PyConnector39-OldDriver-PC',parameters: params},
'Test Python 39 FIPS': { build job: 'RT-FIPS-PyConnector39',parameters: params},
)
}
},
'Test Authentication': {
stage('Test Authentication') {
withCredentials([
string(credentialsId: 'sfctest0-parameters-secret', variable: 'PARAMETERS_SECRET')
]) {
sh '''\
|#!/bin/bash -e
|$WORKSPACE/ci/test_authentication.sh
'''.stripMargin()
}
}
},
'Test WIF': {
stage('Test WIF') {
withCredentials([
string(credentialsId: 'sfctest0-parameters-secret', variable: 'PARAMETERS_SECRET')
]) {
sh '''\
|#!/bin/bash -e
|$WORKSPACE/ci/test_wif.sh
'''.stripMargin()
}
}
},
'Test Revocation Validation': {
stage('Test Revocation Validation') {
withCredentials([
usernamePassword(credentialsId: 'jenkins-snowflakedb-github-app',
usernameVariable: 'GITHUB_USER',
passwordVariable: 'GITHUB_TOKEN')
]) {
try {
sh '$WORKSPACE/ci/test_revocation.sh'
} finally {
archiveArtifacts artifacts: 'revocation-results.json,revocation-report.html', allowEmptyArchive: true
publishHTML(target: [
allowMissing: true,
alwaysLinkToLastBuild: true,
keepAll: true,
reportDir: '.',
reportFiles: 'revocation-report.html',
reportName: 'Revocation Validation Report'
])
}
}
}
}
)
}
}
pipeline {
agent { label 'regular-memory-node' }
options { timestamps() }
environment {
COMMIT_SHA_LONG = sh(returnStdout: true, script: "echo \$(git rev-parse " + "HEAD)").trim()
// environment variables for semgrep_agent (for findings / analytics page)
// remove .git at the end
// remove SCM URL + .git at the end
BASELINE_BRANCH = "${env.CHANGE_TARGET}"
}
stages {
stage('Checkout') {
steps {
checkout scm
}
}
}
}
def authenticatedGithubCall(url) {
withCredentials([
usernamePassword(credentialsId: 'jenkins-snowflakedb-github-app',
usernameVariable: 'GITHUB_USER',
passwordVariable: 'GITHUB_TOKEN'),
]) {
try {
def encodedAuth = Base64.getEncoder().encodeToString(
"${GITHUB_USER}:${GITHUB_TOKEN}".getBytes(java.nio.charset.StandardCharsets.UTF_8)
)
def authHeaderValue = "Basic ${encodedAuth}"
def connection = new URL(url).openConnection()
connection.setRequestProperty("Authorization", authHeaderValue)
if (connection.getResponseCode() >= 300) {
println("ERROR: Status fetch from ${url} returned ${connection.getResponseCode()}")
println(connection.getErrorStream().getText())
return null
}
return new groovy.json.JsonSlurperClassic().parseText(connection.getInputStream().getText())
} catch(Exception e) {
println("Exception fetching ${url}: ${e}")
return null
}
}
}
def wgetUpdateGithub(String state, String folder, String targetUrl, String seconds) {
def ghURL = "https://api.github.com/repos/snowflakedb/snowflake-connector-python/statuses/$COMMIT_SHA_LONG"
def data = JsonOutput.toJson([state: "${state}", context: "jenkins/${folder}",target_url: "${targetUrl}"])
sh "wget ${ghURL} --spider -q --header='Authorization: token $GIT_PASSWORD' --post-data='${data}'"
}