From: Thanh Ha Date: Sat, 4 Aug 2018 20:22:58 +0000 (-0400) Subject: Add Jenkins Sandbox Cleanup job X-Git-Tag: v0.24.0~17^2 X-Git-Url: https://gerrit.linuxfoundation.org/infra/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F22%2F12122%2F2;p=releng%2Fglobal-jjb.git Add Jenkins Sandbox Cleanup job 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 --- diff --git a/docs/jjb/lf-ci-jobs.rst b/docs/jjb/lf-ci-jobs.rst index 0711e93e..dc9690e5 100644 --- a/docs/jjb/lf-ci-jobs.rst +++ b/docs/jjb/lf-ci-jobs.rst @@ -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 -------------- diff --git a/jjb/lf-ci-jobs.yaml b/jjb/lf-ci-jobs.yaml index 8301b654..7bf8643e 100644 --- a/jjb/lf-ci-jobs.yaml +++ b/jjb/lf-ci-jobs.yaml @@ -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 @@ -413,6 +415,59 @@ 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 index 00000000..c1969738 --- /dev/null +++ b/shell/jenkins-sandbox-cleanup.sh @@ -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