From 9006639a58df8ba11504f7d880658eed5bf46ee0 Mon Sep 17 00:00:00 2001
From: Adar Nimrod <nimrod@shore.co.il>
Date: Sat, 13 May 2017 10:17:57 +0300
Subject: [PATCH] - Added Tox env to import role to Ansible Galaxy. - Updated
 Jenkinsfile to use Tox.

---
 Jenkinsfile | 29 +++++++++++++++++++++--------
 tox.ini     |  5 +++++
 2 files changed, 26 insertions(+), 8 deletions(-)

diff --git a/Jenkinsfile b/Jenkinsfile
index bc1cf2e..57e457e 100644
--- a/Jenkinsfile
+++ b/Jenkinsfile
@@ -1,25 +1,38 @@
+/*
+Jenkins pipeline for testing an Ansible role.
+Required software on the agent:
+- Python 2.7.
+- Tox.
+- Vagrant.
+- Virtualbox.
+*/
 pipeline {
     agent any
+    environment {
+        VBOX_HWVIRTEX       = off
+    }
     stages {
         stage('install') {
             steps {
-                sh 'git submodule update --init'
-                sh 'virtualenv example'
-                sh '. example/bin/activate && pip install -r tests/requirements.txt'
-                sh '. example/bin/activate && ansible-galaxy install git+file://$(pwd),$(git rev-parse --abbrev-ref HEAD) -p .molecule/roles'
-                sh '. example/bin/activate && molecule dependency'
+                sh 'git submodule update --init --recursive'
             }
         }
         stage('test') {
             steps {
-                sh '. example/bin/activate && pre-commit run --all-files'
-                // sh '. example/bin/activate && molecule test --platform all'
+                parallel (
+                    'pre-commit': {
+                        sh 'tox -e pre-commit'
+                    }
+                    'molecule': {
+                        sh 'tox'
+                    }
+                )
             }
         }
     }
     post {
         success {
-            sh '. example/bin/activate && ansible-galaxy import -v'
+            sh 'tox -e import'
         }
     }
 }
diff --git a/tox.ini b/tox.ini
index fca4622..c80d480 100644
--- a/tox.ini
+++ b/tox.ini
@@ -24,3 +24,8 @@ commands =
     sh -c "ansible-galaxy install git+file://$(pwd),$(git rev-parse --abbrev-ref HEAD) -p .molecule/roles"
     molecule dependency
     pre-commit run --all-files
+
+[testenv:import]
+envdir = {toxinidir}/.tox/molecule
+deps = -rtests/requirements.txt
+commands = ansible-galaxy import -v
-- 
GitLab