Improved checking of already created stacks to deploy pipeline

Change-Id: I00db07193bb4c2c1fd39ba22106651e9f43975eb
diff --git a/cicd-lab-pipeline.groovy b/cicd-lab-pipeline.groovy
index e1b40c7..6705f9b 100644
--- a/cicd-lab-pipeline.groovy
+++ b/cicd-lab-pipeline.groovy
@@ -81,9 +81,11 @@
                 openstackCloud = openstack.createOpenstackEnv(OPENSTACK_API_URL, OPENSTACK_API_CREDENTIALS, OPENSTACK_API_PROJECT)
                 openstack.getKeystoneToken(openstackCloud, openstackEnv)
                 wrap([$class: 'BuildUser']) {
-                    def existingStacks = openstack.getStacksForNameContains(openstackCloud, "${env.BUILD_USER_ID}-${JOB_NAME}", openstackEnv)
-                    if(existingStacks.size() > _MAX_PERMITTED_STACKS){
-                        throw new Exception("You cannot create new stack, you already have ${_MAX_PERMITTED_STACKS} stacks of this type (${JOB_NAME}). \nStack names: ${existingStacks}")
+                    if (env.BUILD_USER_ID && !env.BUILD_USER_ID.equals("jenkins")) {
+                        def existingStacks = openstack.getStacksForNameContains(openstackCloud, "${env.BUILD_USER_ID}-${JOB_NAME}", openstackEnv)
+                        if(existingStacks.size() >= _MAX_PERMITTED_STACKS){
+                            throw new Exception("You cannot create new stack, you already have ${_MAX_PERMITTED_STACKS} stacks of this type (${JOB_NAME}). \nStack names: ${existingStacks}")
+                        }
                     }
                 }
             }
diff --git a/lab-pipeline.groovy b/lab-pipeline.groovy
index b00c018..c488210 100644
--- a/lab-pipeline.groovy
+++ b/lab-pipeline.groovy
@@ -94,9 +94,11 @@
                     // Verify possibility of create stack for given user and stack type
                     //
                     wrap([$class: 'BuildUser']) {
-                        def existingStacks = openstack.getStacksForNameContains(openstackCloud, "${env.BUILD_USER_ID}-${JOB_NAME}", openstackEnv)
-                        if(existingStacks.size() > _MAX_PERMITTED_STACKS){
-                            throw new Exception("You cannot create new stack, you already have ${_MAX_PERMITTED_STACKS} stacks of this type (${JOB_NAME}). \nStack names: ${existingStacks}")
+                        if (env.BUILD_USER_ID && !env.BUILD_USER_ID.equals("jenkins")) {
+                            def existingStacks = openstack.getStacksForNameContains(openstackCloud, "${env.BUILD_USER_ID}-${JOB_NAME}", openstackEnv)
+                            if(existingStacks.size() >= _MAX_PERMITTED_STACKS){
+                                throw new Exception("You cannot create new stack, you already have ${_MAX_PERMITTED_STACKS} stacks of this type (${JOB_NAME}). \nStack names: ${existingStacks}")
+                            }
                         }
                     }
                     // launch stack