-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathJenkinsfile.movedata
84 lines (63 loc) · 3.01 KB
/
Jenkinsfile.movedata
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
import groovy.json.JsonSlurper
@Library('conservify') _
properties([
buildDiscarder(logRotator(numToKeepStr: '1')),
disableConcurrentBuilds(),
])
def execute(url, query) {
writeFile(file: "query.sql", text: query)
return sh(returnStdout: true, script: "docker run --log-driver none --rm -i postgres psql '${url}' -tq < query.sql").split("\n")
}
timestamps {
node ("jenkins-aws-ubuntu") {
try {
def workEnv = "prod"
def branchName = params.DeployBranch ?: "develop"
def include = params.Move ?: ""
def job = "cloud/" + "develop"
def now = new Date()
def stamp = now.format("yyyyMMdd-HHmmss", TimeZone.getTimeZone('UTC'))
cleanWs()
def ws = conservifyTerraformWorkspace(env: workEnv)
stage ('processing') {
withCredentials([usernamePassword(credentialsId: 'jenkins-artifact-download', usernameVariable: 'JENKINS_USER', passwordVariable: 'JENKINS_PASSWORD')]) {
copyArtifacts(projectName: job, flatten: true, excludes: "**/*.tar")
stage ('move-json') {
if ("json" in include) {
sh "FIELDKIT_TIME_SCALE_URL='${ws.timescaledb_url.value}' FIELDKIT_POSTGRES_URL='${ws.database_url.value}' ./movedata --json --schema-id 7"
}
}
stage ('move-binary') {
if ("binary-all" in include) {
sh "rm -f move-binary.log"
def stations = execute(ws.database_url.value, "SELECT id FROM fieldkit.station ORDER BY id DESC")
for (def stationId : stations) {
print(stationId)
sh "FIELDKIT_TIME_SCALE_URL='${ws.timescaledb_url.value}' FIELDKIT_POSTGRES_URL='${ws.database_url.value}' ./movedata --binary --station-id ${stationId} >> move-binary.log"
}
}
def matcher = include =~ /binary-(\d+)/
if (matcher) {
sh "rm -f move-binary.log"
def stationId = matcher[0][1]
sh "FIELDKIT_TIME_SCALE_URL='${ws.timescaledb_url.value}' FIELDKIT_POSTGRES_URL='${ws.database_url.value}' ./movedata --binary --station-id ${stationId} >> move-binary.log"
}
}
stage ('move-ingestions') {
def matcher = include =~ /ingestions-(\d+)/
if (matcher) {
sh "rm -f move-ingestions.log"
def stationId = matcher[0][1]
sh "FIELDKIT_TIME_SCALE_URL='${ws.timescaledb_url.value}' FIELDKIT_POSTGRES_URL='${ws.database_url.value}' ./movedata --ingestions --station-id ${stationId} >> move-ingestions.log"
}
}
notifySuccess()
}
}
}
catch (Exception e) {
notifyFailure(e)
throw e
}
}
}