Add Jenkins Sandbox Cleanup job 22/12122/2
authorThanh Ha <thanh.ha@linuxfoundation.org>
Sat, 4 Aug 2018 20:22:58 +0000 (16:22 -0400)
committerThanh Ha <thanh.ha@linuxfoundation.org>
Tue, 7 Aug 2018 14:12:47 +0000 (10:12 -0400)
This cleanup job runs weekly on Saturdays to clear out Sandbox
jobs and views from the system.

The benefit of this is that it uses the same version of JJB as
the other CI jobs whereas the traditional cron job we put in puppet
does not often get updated to match the right version.

Issue: RELENG-1118
Change-Id: I2229d66f637bd5aab203a3bbf12aa1e677a471a1
Signed-off-by: Thanh Ha <thanh.ha@linuxfoundation.org>
docs/jjb/lf-ci-jobs.rst
jjb/lf-ci-jobs.yaml
shell/jenkins-sandbox-cleanup.sh [new file with mode: 0644]

index 0711e93..dc9690e 100644 (file)
@@ -13,6 +13,7 @@ Recommended jobs that should be deployed for CI using Gerrit.
 :Includes:
 
     - gerrit-jenkins-cfg-merge
+    - gerrit-jenkins-sandbox-cleanup
     - gerrit-jjb-deploy-job
     - gerrit-jjb-merge
     - gerrit-jjb-verify
@@ -25,6 +26,7 @@ Recommended jobs that should be deployed CI using GitHub.
 :Includes:
 
     - github-jenkins-cfg-merge
+    - github-jenkins-sandbox-cleanup
     - github-jjb-deploy-job
     - github-jjb-merge
     - github-jjb-verify
@@ -314,6 +316,30 @@ Troubleshooting
     inspected.
 
 
+Jenkins Sandbox Cleanup
+-----------------------
+
+Cleanup Jenkins Sandbox of jobs and views periodically.
+
+:Template names:
+
+    - {project-name}-jenkins-sandbox-cleanup
+    - gerrit-jenkins-sandbox-cleanup
+    - github-jenkins-sandbox-cleanup
+
+:Comment Trigger: NONE
+
+:Required parameters:
+
+    :build-node: The node to run build on.
+    :jenkins-ssh-credential: Credential to use for SSH. (Generally
+        should be configured in defaults.yaml)
+
+:Optional parameters:
+
+    :cron: Schedule to run job. (default: '0 8 * * 6')
+
+
 JJB Deploy Job
 --------------
 
index 8301b65..7bf8643 100644 (file)
@@ -4,6 +4,7 @@
 
     jobs:
       - gerrit-jenkins-cfg-merge
+      - gerrit-jenkins-sandbox-cleanup
       - gerrit-jjb-deploy-job
       - gerrit-jjb-merge
       - gerrit-jjb-verify
@@ -13,6 +14,7 @@
 
     jobs:
       - github-jenkins-cfg-merge
+      - github-jenkins-sandbox-cleanup
       - github-jjb-deploy-job
       - github-jjb-merge
       - github-jjb-verify
           white-list-target-branches:
             - '{branch}'
 
+
+###########################
+# JENKINS SANDBOX CLEANUP #
+###########################
+
+- lf_jenkins_sandbox_cleanup: &lf_jenkins_sandbox_cleanup
+    name: lf-jenkins-sandbox-cleanup
+
+    ######################
+    # Default parameters #
+    ######################
+
+    build-timeout: 30
+    # Run every Saturday at 08:00 UTC
+    cron: '0 8 * * 6'
+
+    #####################
+    # Job Configuration #
+    #####################
+
+    project-type: freestyle
+    node: '{build-node}'
+    concurrent: true
+
+    parameters:
+      - lf-infra-jjb-parameters:
+          jjb-version: '{jjb-version}'
+
+    triggers:
+      - timed: '{obj:cron}'
+
+    builders:
+      - lf-infra-jjbini
+      - shell: !include-raw-escape:
+          - ../shell/jjb-install.sh
+          - ../shell/jenkins-sandbox-cleanup.sh
+          - ../shell/jjb-cleanup.sh
+
+- job-template:
+    name: '{project-name}-jenkins-sandbox-cleanup'
+    id: gerrit-jenkins-sandbox-cleanup
+    <<: *lf_jjb_common
+    # yamllint disable-line rule:key-duplicates
+    <<: *lf_jenkins_sandbox_cleanup
+
+- job-template:
+    name: '{project-name}-jenkins-sandbox-cleanup'
+    id: github-jenkins-sandbox-cleanup
+    <<: *lf_jjb_common
+    # yamllint disable-line rule:key-duplicates
+    <<: *lf_jenkins_sandbox_cleanup
+
+
 ##################
 # JJB DEPLOY JOB #
 ##################
diff --git a/shell/jenkins-sandbox-cleanup.sh b/shell/jenkins-sandbox-cleanup.sh
new file mode 100644 (file)
index 0000000..c196973
--- /dev/null
@@ -0,0 +1,16 @@
+#!/bin/bash
+# SPDX-License-Identifier: EPL-1.0
+##############################################################################
+# Copyright (c) 2018 The Linux Foundation and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Eclipse Public License v1.0
+# which accompanies this distribution, and is available at
+# http://www.eclipse.org/legal/epl-v10.html
+##############################################################################
+# Deletes all jobs on a Jenkins Sandbox system.
+echo "---> jenkins-sandbox-cleanup.sh"
+
+set -eux -o pipefail
+
+bash -c "/usr/bin/yes 2>/dev/null || true" | jenkins-jobs -s sandbox delete-all