-
Notifications
You must be signed in to change notification settings - Fork 2
/
Jenkinsfile
77 lines (72 loc) · 1.8 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
pipeline {
environment {
registry = "https://docker-registry.it.csiro.au"
imageName = "aemvl/backend"
registryCredential = "sam-nexus"
}
agent none
options {
buildDiscarder(logRotator(numToKeepStr: '25', artifactNumToKeepStr: '4'))
disableConcurrentBuilds()
}
stages {
stage('Setup & Test') {
agent {
docker {
image 'continuumio/miniconda3'
args '-u root:root'
}
}
steps {
sh 'conda create -n aemvl-backend python=3.6'
sh 'echo "source activate aemvl-backend" > ~/.bashrc'
sh 'PATH=/opt/conda/envs/env/bin:$PATH'
sh 'conda install --file requirements.txt'
sh 'GDAL_DATA=/opt/miniconda3/envs/aemvl-backend/share/epsg_csv'
sh 'pip install pylint pytest python-dotenv'
echo "Unit Tests"
sh 'py.test --verbose --junit-xml test-reports/results.xml'
echo "Style check"
sh '''
pylint aemvl_backend || true
'''
}
post {
always {
junit 'test-reports/results.xml'
sh 'sh clean.sh'
}
}
}
stage('Build Image') {
agent { label 'master' }
steps {
script {
SECRET = sh (script:"date +%s | sha256sum | base64 | head -c 32 ; echo", returnStdout: true).trim()
if( "${env.BRANCH_NAME}" != "master" ) {
GIT_TAG = "${env.BRANCH_NAME}-${env.BUILD_NUMBER}"
}
else {
GIT_TAG = "${env.BUILD_NUMBER}"
}
image = docker.build("${imageName}", " --build-arg version=${GIT_TAG} --build-arg secret=${SECRET} .")
println "Newly generated image, " + image.id
}
}
}
stage('Push Image') {
agent { label 'master' }
steps {
script {
docker.withRegistry(registry, registryCredential)
{
image.push("${env.BRANCH_NAME}")
if ( "${env.BRANCH_NAME}" == "master" ) {
image.push("latest")
}
}
}
}
}
}
}