Merge "Add Jenkins Sandbox Cleanup job"
authorJeremy Phelps <jphelps@linuxfoundation.org>
Fri, 10 Aug 2018 00:02:26 +0000 (00:02 +0000)
committerGerrit Code Review <gerrit@linuxfoundation.org>
Fri, 10 Aug 2018 00:02:26 +0000 (00:02 +0000)
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 c07bd03..5532a3e 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