-
Notifications
You must be signed in to change notification settings - Fork 2
/
Jenkinsfile
123 lines (114 loc) · 4.9 KB
/
Jenkinsfile
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
pipeline {
agent {
docker {
reuseNode false
image 'justaddcoffee/ubuntu20-python-3-8-5-dev:8'
}
}
// triggers{
// cron('0 8 * * 2,5')
// }
environment {
RUNSTARTDATE = sh(script: "echo `date +%Y%m%d`", returnStdout: true).trim()
}
options {
timestamps()
disableConcurrentBuilds()
}
stages {
// Very first: pause for a minute to give a chance to
// cancel and clean the workspace before use.
stage('Ready and clean') {
steps {
// Give us a minute to cancel if we want.
sleep time: 30, unit: 'SECONDS'
}
}
stage('Initialize') {
steps {
// print some info
dir('./gitrepo') {
sh 'env > env.txt'
sh 'echo $BRANCH_NAME > branch.txt'
sh 'echo "$BRANCH_NAME"'
sh 'cat env.txt'
sh 'cat branch.txt'
sh "echo $RUNSTARTDATE > dow.txt"
sh "echo $RUNSTARTDATE"
sh "python3.8 --version"
sh "id"
sh "whoami" // this should be jenkinsuser
// if the above fails, then the docker host didn't start the docker
// container as a user that this image knows about. This will
// likely cause lots of problems (like trying to write to $HOME
// directory that doesn't exist, etc), so we should fail here and
// have the user fix this
}
}
}
stage('Build utilities') {
steps {
dir('./gitrepo') {
git(
url: 'https://github.com/Knowledge-Graph-Hub/knowledge-graph-hub.github.io',
branch: env.BRANCH_NAME
)
sh '/usr/bin/python3.8 -m venv venv'
sh '. venv/bin/activate'
// Now move on to the actual install + reqs
sh './venv/bin/pip install -r requirements.txt'
}
}
}
stage('Make manifest') {
steps {
dir('./gitrepo') {
withCredentials([
file(credentialsId: 's3cmd_kg_hub_push_configuration', variable: 'S3CMD_CFG'),
file(credentialsId: 'aws_kg_hub_push_json', variable: 'AWS_JSON'),
string(credentialsId: 'aws_kg_hub_access_key', variable: 'AWS_ACCESS_KEY_ID'),
string(credentialsId: 'aws_kg_hub_secret_key', variable: 'AWS_SECRET_ACCESS_KEY')]) {
script {
def run_make_manifest = sh(
script: '. venv/bin/activate && cd utils/ && python make_kg_manifest.py --bucket kg-hub-public-data --outpath MANIFEST.yaml --maximum 75', returnStatus: true
)
if (run_make_manifest == 0) {
if (env.BRANCH_NAME != 'master') { // upload raw to s3 if we're on correct branch
echo "Will not push if not on main branch."
} else {
sh 'ls -lh utils/'
sh 's3cmd -c $S3CMD_CFG --acl-public --mime-type=plain/text --cf-invalidate put utils/MANIFEST.yaml s3://kg-hub-public-data/ '
sh 's3cmd -c $S3CMD_CFG --acl-public --mime-type=plain/text --cf-invalidate put utils/manifest.log s3://kg-hub-public-data/ '
sh 'mkdir -p utils/logs/ && touch utils/logs/placeholder' //We want a logs folder, whether we have new logs or not
sh 's3cmd -c $S3CMD_CFG --acl-public --mime-type=plain/text --cf-invalidate put -r utils/logs/ s3://kg-hub-public-data/ '
}
} else { // 'make_kg_manifest.py' failed.
echo "Failed to make manifest."
currentBuild.result = "FAILED"
}
}
}
}
}
}
}
post {
always {
echo 'In always'
echo 'Cleaning workspace...'
cleanWs()
}
success {
echo 'I succeeded!'
}
unstable {
echo 'I am unstable :/'
}
failure {
echo 'I failed :('
}
changed {
echo 'Things were different before...'
}
}
}