-
Notifications
You must be signed in to change notification settings - Fork 73
/
Jenkinsfile
84 lines (74 loc) · 2.96 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
def testReport = 'test-report.xml'
def stagingBucket = 'internal.clyqz.com'
def stagingPrefix = '/docs/whotracksme'
def productionBucket = 'cliqz-tracking-monitor'
def productionPrefix = ''
node('docker && !gpu && eu-central-1') {
stage ('Checkout') {
checkout([
$class: 'GitSCM',
branches: [[name: 'refs/heads/'+env.BRANCH_NAME]],
extensions: [[$class: 'GitLFSPull']],
userRemoteConfigs: [
[refspec: '+refs/heads/*:refs/remotes/origin/* +refs/pull/*/head:refs/remotes/origin/PR-* +refs/tags/*:refs/remotes/origin/*',
url: 'https://github.com/cliqz-oss/whotracks.me.git']
]
])
}
def img
stage('Build Docker Image') {
img = docker.build('whotracksme', '.')
}
img.inside() {
try {
stage('Install') {
sh("python -m pip install --user -e '.[dev]'")
}
stage('Test') {
try {
sh(script: "pytest --junit-xml=${testReport}")
} catch(err) {
junit(testReport)
currentBuild.result = "FAILURE"
}
}
stage('Build site') {
sh('/home/jenkins/.local/bin/whotracksme website')
}
stage('Publish artifacts') {
def tag = env.TAG_NAME
def suffix = '-pypi'
// Only publish a version if tag ends with `suffix`.
if (tag != null && tag.endsWith(suffix)) {
// Extract part of the tag before suffix.
def version = tag.substring(0, tag.length() - suffix.length())
withCredentials([usernamePassword(
credentialsId: '3fc94ee4-8e89-4973-b34e-e37df209a74e',
passwordVariable: 'password',
usernameVariable: 'user'
)]) {
sh('rm -fr dist/ whotracksme.egg-info')
sh("WTM_VERSION=${version} python setup.py install")
sh("WTM_VERSION=${version} python setup.py sdist bdist_wheel")
sh("twine upload --username cliqz-oss --password $password dist/*")
}
}
}
stage('Publish Site') {
def deployArgs = ''
if (env.BRANCH_NAME.contains('PR')) {
deployArgs = "${stagingBucket} ${stagingPrefix}/${env.BRANCH_NAME}"
} else if (env.TAG_NAME != null) {
deployArgs = "${productionBucket} ${productionPrefix} --production"
} else {
deployArgs = "${stagingBucket} ${stagingPrefix}/latest"
}
sh("python deploy_to_s3.py ${deployArgs}")
}
} finally {
// cleanup
sh('rm -rf _site; rm -rf .sass-cache')
}
}
junit(testReport)
}