-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathJenkinsfile
104 lines (96 loc) · 3.75 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
pipeline {
agent {
docker {
image 'docker:24.0.6-git'
}
}
environment {
CODECOV_TOKEN = credentials('CODECOV_TOKEN_rest_variantvalidator')
CONTAINER_SUFFIX = "${BUILD_NUMBER}"
DATA_VOLUME = "/root/variantvalidator_data/"
}
stages {
stage("Clone Repository Remove dangling docker components and Create Docker Network") {
steps {
checkout scm
sh 'docker system prune --all --volumes --force'
}
}
stage("Switch to Git Branch") {
steps {
sh "git checkout ${BRANCH_NAME}"
sh "git pull"
}
}
stage("Install Docker Compose") {
steps {
sh 'apk update && apk add docker-compose'
}
}
stage("Check and Create Directories") {
steps {
script {
sh """
if [ ! -d "${DATA_VOLUME}seqdata" ]; then
mkdir -p ${DATA_VOLUME}seqdata
fi
if [ ! -d "${DATA_VOLUME}logs" ]; then
mkdir -p ${DATA_VOLUME}logs
fi
ls -l ${DATA_VOLUME}
"""
}
}
}
stage("Build and Run containers") {
steps {
script {
sh """
docker-compose --project-name rest-variantvalidator-ci build --no-cache rv-vvta rv-vdb rv-seqrepo rest-variantvalidator
docker-compose --project-name rest-variantvalidator-ci up -d rv-vvta && docker-compose --project-name rest-variantvalidator-ci up -d rv-vdb && docker-compose --project-name rest-variantvalidator-ci up -d rv-seqrepo && docker-compose --project-name rest-variantvalidator-ci up -d rest-variantvalidator
"""
}
}
}
stage("Connect and run Pytest") {
steps {
script {
def connectionSuccessful = false
for (int attempt = 1; attempt <= 5; attempt++) {
echo "Attempt $attempt to connect to the database..."
def exitCode = sh(script: '''
docker-compose exec -e PGPASSWORD=uta_admin rest-variantvalidator-${CONTAINER_SUFFIX} psql -U uta_admin -d vvta -h rv-vvta-${CONTAINER_SUFFIX} -p 54321
''', returnStatus: true)
if (exitCode == 0) {
connectionSuccessful = true
echo "Connected successfully! Running tests..."
break
}
echo "Connection failed. Waiting for 60 seconds before the next attempt..."
sleep 60
}
if (!connectionSuccessful) {
error "All connection attempts failed. Exiting..."
}
}
}
}
stage("Run Pytest and Codecov") {
steps {
script {
sh 'docker-compose exec rest-variantvalidator-${CONTAINER_SUFFIX} pytest --cov=rest_VariantValidator --cov-report=term tests/'
sh 'docker-compose exec rest-variantvalidator-${CONTAINER_SUFFIX} codecov -t $CODECOV_TOKEN -b ${BRANCH_NAME}'
}
}
}
}
post {
always {
script {
sh 'docker-compose down -v'
sh 'docker network rm $DOCKER_NETWORK'
sh 'docker system prune --all --volumes --force'
}
}
}
}