]> git.apps.os.sepia.ceph.com Git - ceph-build.git/commitdiff
jenkins-job-builder: Delete stale jobs 880/head
authorDavid Galloway <dgallowa@redhat.com>
Tue, 3 Oct 2017 19:09:01 +0000 (15:09 -0400)
committerDavid Galloway <dgallowa@redhat.com>
Tue, 31 Oct 2017 14:22:51 +0000 (10:22 -0400)
Signed-off-by: David Galloway <dgallowa@redhat.com>
jenkins-job-builder/build/build

index 26cad72a19803f8abc39298cdc5a9eb672c3d3cd..50675219db1e732801cea293fc198571c3c0b67a 100644 (file)
@@ -9,7 +9,7 @@
 set -ex
 
 # the following two methods exist in scripts/build_utils.sh
-pkgs=( "jenkins-job-builder==2.0.0.0b2" )
+pkgs=( "jenkins-job-builder==2.0.0.0b2" "jq" )
 install_python_packages "pkgs[@]"
 
 # Wipe out JJB's cache if $FORCE is set.
@@ -28,6 +28,9 @@ password=$JOB_BUILDER_PASS
 url=$JENKINS_URL
 EOF
 
+# Make a temp dir to store job configs created using `jenkins-jobs test`
+TEMPDIR=$(mktemp -d)
+
 # Test every definition if available in the current repository and update the jobs
 # if they do define one (they should always define their definitions)
 for dir in `find . -maxdepth 1 -path ./.git -prune -o -type d -print`; do
@@ -49,7 +52,7 @@ for dir in `find . -maxdepth 1 -path ./.git -prune -o -type d -print`; do
         # that started it.  This prevents collisions.
         if [[ "$JJB_CONFIG" == "$HOME/.jenkins_jobs.$JENKINS_FQDN.ini" ]]; then
             # Test the definitions first
-            $VENV/jenkins-jobs --log_level DEBUG --conf $JJB_CONFIG test $definitions_dir -o /tmp/output
+            $VENV/jenkins-jobs --log_level DEBUG --conf $JJB_CONFIG test $definitions_dir -o $TEMPDIR
 
             # Update Jenkins with the output if they passed the test phase
             # Note that this needs proper permissions with the right credentials to the
@@ -58,3 +61,12 @@ for dir in `find . -maxdepth 1 -path ./.git -prune -o -type d -print`; do
         fi
     fi
 done
+
+# Delete jobs our master has that didn't get job xml written during `jenkins-jobs test`
+# jenkins-job-builder doesn't get a config written so we `grep -v it` so it doesn't get deleted.
+for JOB in $(curl -s https://$JENKINS_FQDN/api/json | jq -r '.jobs[].name' | grep -v jenkins-job-builder | sort); do
+    if [ ! -f $TEMPDIR/$JOB ]; then
+        echo "Did not find job definition for $JOB.  Deleting!"
+        $VENV/jenkins-jobs --log_level DEBUG --conf $JJB_CONFIG delete $JOB
+    fi
+done