This repository was archived by the owner on Apr 14, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathJenkinsfile
More file actions
134 lines (118 loc) · 4.26 KB
/
Jenkinsfile
File metadata and controls
134 lines (118 loc) · 4.26 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
#!/usr/bin/env groovy
pipeline {
agent any
triggers {
cron('0 6 * * *') // run every day at 11pm PST
}
options {
buildDiscarder(logRotator(daysToKeepStr: '2'))
}
environment {
SF_ROLE="SYSADMIN"
SF_DATABASE="SPLIT"
SF_WAREHOUSE="COMPUTE_WH"
SF_CRED=credentials("SNOWFLAKE")
SF_ACCOUNT="bv23770.us-east-1"
// State File
DATADOG_STATE="./states/datadog.json"
// Python Enviroments
VENV_DATADOG="venv/tap-datadog"
VENV_SF="venv/target-snowflake"
}
stages {
stage('Create States directory') {
steps {
sh "mkdir -p ./states"
}
} // Stage States Directory
stage('Create Venvs') {
parallel {
stage('Venv Datadog') {
environment {
SOURCE_INSTALL='.[dev]'
FLAG="-e"
}
steps {
sh './createVenv.sh "${VENV_DATADOG}" "${SOURCE_INSTALL}" "${FLAG}"'
}
}// stage Venv Datadog
stage('Venv Snowflake') {
environment {
SOURCE_INSTALL='git+https://gitlab.com/meltano/target-snowflake.git@master#egg=target-snowflake'
FLAG="-e"
}
steps {
sh './createVenv.sh "${VENV_SF}" "${SOURCE_INSTALL}" "${FLAG}"'
}
} // Stage Venv Snowflake
stage('State Datadog'){
steps{
setState("${DATADOG_STATE}")
}
}// stage State Datadog
} // Parallel
} // Stage Create Venv
stage('Run Tap-datadog'){
environment{
DATADOG_START_MONTH="2019-07"
DATADOG_START_HOUR="2019-06-17T12"
DATADOG_API_KEY=credentials('DATADOG_API_KEY')
DATADOG_APPLICATION_KEY=credentials('DATADOG_APPLICATION_KEY')
SF_SCHEMA="DATADOG"
SF_CONFIG_FILE="config-snoflake-datadog.json"
TAP_OUTPUT="tap-datadog-output.json"
STDERRFILE="stderr_datadog.out"
}
steps{
script{
sh(returnStdout: false, script: 'set -euo pipefail')
sh(returnStdout: false, script: 'envsubst < config-datadog.json.tpl > config-datadog.json')
sh(returnStdout: false, script: 'envsubst < config-snowflake.json.tpl > "${SF_CONFIG_FILE}"')
status=sh(returnStatus: true, script: '${VENV_DATADOG}/bin/tap-datadog -c config-datadog.json --catalog datadog-properties.json -s "${DATADOG_STATE}" > "${TAP_OUTPUT}" 2>"${STDERRFILE}"')
catchError(status, "Tap-datadog", "Failed to collect data.", "${STDERRFILE}")
status=sh(returnStdout: false, script:'echo -e "\n" >> ${DATADOG_STATE}')
status=sh(returnStatus: true, script: 'cat ${TAP_OUTPUT} | ${VENV_SF}/bin/target-snowflake -c "${SF_CONFIG_FILE}" >> ${DATADOG_STATE} 2>"${STDERRFILE}"')
catchError(status, "Tap-datadog", "Failed to send data.", "${STDERRFILE}")
}
}
}// stage Run Tap-datadog
} // Stages
post{
success{
slackSend(channel: "#analytics-alerts", message: "Tap-datadog Worked.", color: "#008000")
}
always{
cleanWs (
deleteDirs: false,
patterns: [
[pattern: 'config*.json', type: 'INCLUDE'],
[pattern: '*output*.json', type: 'INCLUDE'],
[pattern: 'stderr*.out', type: 'INCLUDE']
]
)
}//always
}// post
} // Pipeline
def setState(state){
def exists = fileExists state
if (exists) {
def file = readFile state
def last = file.split("\n")[file.split("\n").length-1]
writeFile file: state, text : last
def count = sh(returnStdout:true, script:'cat '+ state + ' | tr \' \' \'\n\' | grep bookmark | wc -l').trim()
echo count
sh(returnStdout:true, script:'cat ' + state)
}
else {
writeFile file: state, text: '{}'
}
}
def catchError(status, tap, message, stderrfile){
if (status != 0) {
def output = readFile(stderrfile)
print(output)
slackSend(channel: "#analytics-alerts", message: "*$tap:* $message \n *Reason:* $output", color: "#ff0000")
currentBuild.result = 'FAILED'
error "$message"
}
}