aboutsummaryrefslogtreecommitdiff
path: root/Jenkinsfile
diff options
context:
space:
mode:
Diffstat (limited to 'Jenkinsfile')
-rw-r--r--Jenkinsfile95
1 files changed, 95 insertions, 0 deletions
diff --git a/Jenkinsfile b/Jenkinsfile
new file mode 100644
index 0000000..265e6c6
--- /dev/null
+++ b/Jenkinsfile
@@ -0,0 +1,95 @@
+/* This is intended to test the dev & master branches of the gr-api project,
+ where the tests are entirely self contained
+*/
+
+pipeline {
+ agent any
+
+ triggers {
+ cron('H */6 * * *')
+ pollSCM('H */3 * * *')
+ }
+
+ environment {
+ DATA_SRC = "${env.WORKSPACE}/mnt/"
+
+ AMT_JB_CARER_VENV = "${env.WORKSPACE}/amt-jb-carer-venv"
+ AMT_JB_VENV = "${env.WORKSPACE}/amt-jb-venv"
+ }
+
+ stages {
+ stage('Setup DB'){
+ steps {
+ script {
+ env.DB_NAME = "unittest-amt-jb-" + UUID.randomUUID().toString().replace("-", "").take(12)
+ env.AMT_JB_DB = "postgres://jenkins:123456789@unittest-postgresql.fmt2.grl.internal/${env.DB_NAME}"
+ echo "Using database: ${env.DB_NAME}"
+ }
+
+ sh """
+ PGPASSWORD=123456789 psql -h unittest-postgresql.fmt2.grl.internal -U jenkins -d postgres <<EOF
+ CREATE DATABASE "${env.DB_NAME}" WITH TEMPLATE = template0 ENCODING = 'UTF8';
+ EOF
+ """
+ }
+ }
+
+ stage('setup:amt-jb-carer') {
+ steps {
+ checkout scmGit(
+ branches: [[name: 'master']],
+ extensions: [ cloneOption(shallow: true) ],
+ userRemoteConfigs: [
+ [credentialsId: 'abdeb570-b708-44f3-b857-8a6b06ed9822',
+ url: 'ssh://code.g-r-l.com:6611/panels/amt-jb']
+ ],
+ )
+
+ dir("carer/") {
+ sh 'python3.13 -m venv $AMT_JB_CARER_VENV'
+ sh '$AMT_JB_CARER_VENV/bin/pip install -U setuptools wheel pip'
+ sh '$AMT_JB_CARER_VENV/bin/pip install -r requirements.txt'
+ sh '$AMT_JB_CARER_VENV/bin/python3.13 manage.py migrate --settings=carer.settings.unittest'
+ }
+ }
+ }
+
+ /* Okay, finally we can setup the virtual environment for the actual
+ project itself. gr-api FastAPI doesn't manage any of it's own
+ database so it doesn't need to do any migrations or anything.
+ */
+ stage('setup:amt-jb') {
+ steps {
+ sh 'python3.13 -m venv $AMT_JB_VENV'
+ sh '$AMT_JB_VENV/bin/pip install -U setuptools wheel pip'
+ withCredentials([sshUserPrivateKey(
+ credentialsId: 'abdeb570-b708-44f3-b857-8a6b06ed9822',
+ keyFileVariable: 'SSH_PRIVATE_KEY')]) {
+
+ sh """
+ eval \$(ssh-agent) && ssh-add ${SSH_PRIVATE_KEY} && \
+ ${AMT_JB_VENV}/bin/pip install -r requirements.txt
+ """
+ }
+ }
+ }
+
+ stage('tests') {
+ steps {
+ sh '$AMT_JB_VENV/bin/pytest -v tests'
+ }
+ }
+ }
+ post {
+ always {
+ echo 'One way or another, I have finished'
+ deleteDir() /* clean up our workspace */
+
+ sh """
+ PGPASSWORD=123456789 psql -h unittest-postgresql.fmt2.grl.internal -U jenkins -d postgres <<EOF
+ DROP DATABASE "${env.DB_NAME}";
+ EOF
+ """
+ }
+ }
+}