From 5fd5371445afa9c419fdf22e2b66d77218ac3604 Mon Sep 17 00:00:00 2001
From: Erik Reid <erik.reid@geant.org>
Date: Mon, 15 Jun 2020 08:17:20 +0200
Subject: [PATCH] initial Jenkinsfile

---
 Jenkinsfile      | 84 ++++++++++++++++++++++++++++++++++++++++++++++++
 sonar.properties |  5 +++
 2 files changed, 89 insertions(+)
 create mode 100644 Jenkinsfile
 create mode 100644 sonar.properties

diff --git a/Jenkinsfile b/Jenkinsfile
new file mode 100644
index 00000000..d68115df
--- /dev/null
+++ b/Jenkinsfile
@@ -0,0 +1,84 @@
+// make sure the pip cache is accessible
+def container_args = "-v ${env.JENKINS_HOME}/.cache:/cache:rw,z -e XDG_CACHE_HOME=/cache"
+
+pipeline {
+    agent none
+    stages {
+        stage('init') {
+            agent any
+            steps {
+                script {
+                    def matcher = env.GIT_URL =~ /\/(.*)\.git/
+
+                    if(matcher.find()) {
+                        gitProjectId = matcher[0][1];
+                    }
+                }
+                echo gitProjectId
+            }
+        }
+        stage('test') {
+            parallel {
+
+                stage('test Python 3.6.8 (Centos 7)') {
+                    agent {
+                        docker {
+                            image 'python:3.6.8'
+                            args container_args
+                        }
+                    }
+                    steps {
+                        run_unit_tests('py36')
+                    }
+                }
+
+                stage('test Python 3.7.6') {
+                    agent {
+                        docker {
+                            image 'python:3.7.6'
+                            args container_args
+                        }
+                    }
+                    steps {
+                        run_unit_tests('py37')
+                    }
+                }
+
+                stage('test Python 3.8.3') {
+                    agent {
+                        docker {
+                            image 'python:3.8.3'
+                            args container_args
+                        }
+                    }
+                    steps {
+                        run_unit_tests('py38')
+                    }
+                }
+
+            }
+        }
+        stage('SonarQube analysis') {
+            agent any
+            steps {
+                script {
+                    // must match 'Name' from Jenkins 'Global Tool Configuration'
+                    scannerHome = tool 'sonar-scaner';
+                }
+                // must match 'Name' from Jenkins 'Configure System'
+                withSonarQubeEnv('Project SonarQube') {
+                    sh "${scannerHome}/bin/sonar-scanner -Dproject.settings=./sonar.properties"
+                }
+            }
+
+        }
+    }
+}
+
+void run_unit_tests(tox_env) {
+    sh 'python -m venv venv'
+    sh 'venv/bin/pip install tox'
+    sh "venv/bin/tox -e $tox_env"
+}
+
+
diff --git a/sonar.properties b/sonar.properties
new file mode 100644
index 00000000..4ffb5373
--- /dev/null
+++ b/sonar.properties
@@ -0,0 +1,5 @@
+sonar.projectKey=inventory-provider
+sonar.projectName=Inventory Provider
+sonar.projectVersion=0.x
+sonar.sources=inventory_provider
+sonar.python.coverage.reportPaths=coverage.xml
-- 
GitLab