Delete unmanaged jobs with gerrit-ci-scripts-manual

After change 204611 unmanaged jobs were not deleted anymore, when
running gerrit-ci-scripts-manual. This was intentional, since doing so
would cause all other jobs to be deleted, if creating just a specific
job. Nevertheless, this is inconvenient since unmanaged jobs could
accumulate.

This change implements a check, whether only specific jobs are supposed
to be created/updated and if that is not the case deletes old unmanaged
jobs.

Change-Id: I7261e5fa91dae2f3080f41effcd4c41f4f7de74b
diff --git a/jenkins-docker/master/gerrit-ci-scripts-manual.xml b/jenkins-docker/master/gerrit-ci-scripts-manual.xml
index a1f2d71..141946c 100644
--- a/jenkins-docker/master/gerrit-ci-scripts-manual.xml
+++ b/jenkins-docker/master/gerrit-ci-scripts-manual.xml
@@ -50,7 +50,13 @@
   <concurrentBuild>false</concurrentBuild>
   <builders>
     <hudson.tasks.Shell>
-      <command>jenkins-jobs update jenkins ${JOBS}</command>
+      <command>
+        if test -n "${JOBS}"; then
+          jenkins-jobs update jenkins ${JOBS}
+        else
+          jenkins-jobs update --delete-old jenkins
+        fi
+      </command>
     </hudson.tasks.Shell>
   </builders>
   <publishers/>
diff --git a/jenkins/gerrit-ci-scripts.yaml b/jenkins/gerrit-ci-scripts.yaml
index a3451dc..c903071 100644
--- a/jenkins/gerrit-ci-scripts.yaml
+++ b/jenkins/gerrit-ci-scripts.yaml
@@ -71,5 +71,10 @@
            - '${CHANGE_COMMIT}'
          skip-tag: true
     builders:
-      - shell: jenkins-jobs update jenkins/. ${JOBS}
+      - shell: |
+          if test -n "${JOBS}"; then
+            jenkins-jobs update jenkins ${JOBS}
+          else
+            jenkins-jobs update --delete-old jenkins
+          fi