From 50bb84fc6e18daa187d5047968dc130b215a02c0 Mon Sep 17 00:00:00 2001 From: Eric Ball Date: Thu, 25 Oct 2018 14:54:32 -0700 Subject: [PATCH] Verify jenkins-config files have matching images This verify job will check that for each config file in jenkins-config/clouds/**, there is an image on the cloud provider that matches the IMAGE_NAME field. Issue-ID: RELENG-1133 Change-Id: I9bf79657af27e8c7ff7b63ced2bd8a0dd544e6d6 Signed-off-by: Eric Ball --- .jjb-test/lf-ci-jobs/jenkins-cfg-verify.yaml | 7 ++ docs/jjb/lf-ci-jobs.rst | 27 ++++++ jjb/lf-ci-jobs.yaml | 137 +++++++++++++++++++++++++++ shell/jenkins-verify-images.sh | 30 ++++++ 4 files changed, 201 insertions(+) create mode 100644 .jjb-test/lf-ci-jobs/jenkins-cfg-verify.yaml create mode 100755 shell/jenkins-verify-images.sh diff --git a/.jjb-test/lf-ci-jobs/jenkins-cfg-verify.yaml b/.jjb-test/lf-ci-jobs/jenkins-cfg-verify.yaml new file mode 100644 index 00000000..124b9435 --- /dev/null +++ b/.jjb-test/lf-ci-jobs/jenkins-cfg-verify.yaml @@ -0,0 +1,7 @@ +--- +- project: + name: jenkins-cfg-verify + jobs: + - "gerrit-jenkins-cfg-verify" + + project-name: ci-management diff --git a/docs/jjb/lf-ci-jobs.rst b/docs/jjb/lf-ci-jobs.rst index a394741d..8c0ad44b 100644 --- a/docs/jjb/lf-ci-jobs.rst +++ b/docs/jjb/lf-ci-jobs.rst @@ -282,6 +282,33 @@ Troubleshooting used to push to Jenkins. In the event of a job failure this file can be inspected. + .. _lf-global-jjb-jenkins-cfg-verify: + +Jenkins Configuration Verify +---------------------------- + +Jenkins job to verify the Global Jenkins configuration. + +Requires the ``clouds-yaml`` file to be setup on the Jenkins host. + +:Template names: + + - {project-name}-jenkins-cfg-verify + - gerrit-jenkins-cfg-verify + - github-jenkins-cfg-verify + +:Optional parameters: + + :branch: Git branch to build against. (default: master) + :git-url: URL to clone project from. (default: $GIT_URL/$GERRIT_PROJECT) + +This job is not part of the "{project-name}-ci-jobs" group. It must be called +explicitly. + +Example: + +.. literalinclude:: ../../.jjb-test/lf-ci-jobs/jenkins-cfg-verify.yaml + :language: yaml Jenkins Sandbox Cleanup ----------------------- diff --git a/jjb/lf-ci-jobs.yaml b/jjb/lf-ci-jobs.yaml index 638716e9..da70ba3f 100644 --- a/jjb/lf-ci-jobs.yaml +++ b/jjb/lf-ci-jobs.yaml @@ -375,6 +375,143 @@ white-list-target-branches: - '{branch}' +########################################### +# Jenkins Configuration Management Verify # +########################################### + +- lf_jenkins_configuration: &lf_jenkins_cfg_verify + name: lf-jenkins-cfg-verify + + ###################### + # Default parameters # + ###################### + + branch: master + build-days-to-keep: 7 + disable-job: false + git-url: '$GIT_URL/$GERRIT_PROJECT' + github-url: 'https://github.com' + openstack-cloud: vex + submodule-timeout: 10 + + gerrit_verify_triggers: + - patchset-created-event: + exclude-drafts: true + exclude-trivial-rebase: false + exclude-no-code-change: false + - draft-published-event + - comment-added-contains-event: + comment-contains-value: '^Patch Set[ ]+[0-9]+:([ ]+|[\n]+)(recheck|reverify)$' + + gerrit_trigger_file_paths: + - compare-type: REG_EXP + pattern: 'jenkins-config\/.*' + + # github_included_regions MUST match gerrit_trigger_file_paths + github_included_regions: + - 'jenkins-config\/.*' + + ##################### + # Job Configuration # + ##################### + + project-type: freestyle + node: '{build-node}' + concurrent: true + disabled: '{disable-job}' + + properties: + - lf-infra-properties: + project: '{project}' + build-days-to-keep: 1 + + parameters: + - lf-infra-parameters: + project: '{project}' + stream: '' + branch: master + lftools-version: '{lftools-version}' + + wrappers: + - lf-infra-wrappers: + build-timeout: 10 + jenkins-ssh-credential: '{jenkins-ssh-credential}' + - config-file-provider: + # Listed after to override openstack-infra-wrappers clouds.yaml + # definition + files: + - file-id: clouds-yaml + target: '$HOME/.config/openstack/clouds.yaml' + - file-id: npmrc + target: '$HOME/.npmrc' + - file-id: pipconf + target: '$HOME/.config/pip/pip.conf' + + builders: + - lf-infra-pre-build + - inject: + properties-content: OS_CLOUD={openstack-cloud} + - shell: !include-raw-escape: ../shell/jenkins-verify-images.sh + + publishers: + - lf-infra-publish + +- job-template: + name: '{project-name}-jenkins-cfg-verify' + id: gerrit-jenkins-cfg-verify + <<: *lf_jenkins_cfg_verify + + scm: + - lf-infra-gerrit-scm: + git-url: '{git-url}' + refspec: 'refs/heads/{branch}' + branch: '{branch}' + submodule-recursive: true + submodule-timeout: '{submodule-timeout}' + choosing-strategy: default + jenkins-ssh-credential: '{jenkins-ssh-credential}' + + triggers: + - gerrit: + server-name: '{gerrit-server-name}' + trigger-on: '{obj:gerrit_verify_triggers}' + projects: + - project-compare-type: ANT + project-pattern: '{project}' + branches: + - branch-compare-type: ANT + branch-pattern: '**/{branch}' + file-paths: '{obj:gerrit_trigger_file_paths}' + +- job-template: + name: '{project-name}-jenkins-cfg-verify' + id: github-jenkins-cfg-verify + <<: *lf_jenkins_cfg_verify + + properties: + - github: + url: '{github-url}/{github-org}/{project}' + + scm: + - lf-infra-github-scm: + url: '{git-clone-url}{github-org}/{project}' + refspec: '+refs/pull/*:refs/remotes/origin/pr/*' + branch: '$sha1' + submodule-recursive: '{submodule-recursive}' + submodule-timeout: '{submodule-timeout}' + choosing-strategy: default + jenkins-ssh-credential: '{jenkins-ssh-credential}' + + triggers: + - github-pull-request: + trigger-phrase: '^(recheck|reverify)$' + only-trigger-phrase: false + status-context: 'Jenkins CFG Verify' + permit-all: true + github-hooks: true + included-regions: '{obj:github_included_regions}' + white-list-target-branches: + - '{branch}' ########################### # JENKINS SANDBOX CLEANUP # diff --git a/shell/jenkins-verify-images.sh b/shell/jenkins-verify-images.sh new file mode 100755 index 00000000..aed8d12f --- /dev/null +++ b/shell/jenkins-verify-images.sh @@ -0,0 +1,30 @@ +#!/bin/bash -l +# 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 +############################################################################## +echo "---> jenkins-verify-images.sh" +# Verifies that openstack contains an image for each config file defined in the +# jenkins-config/clouds/openstack directory. + +error=false + +for file in jenkins-config/clouds/openstack/*/*; do + # Set the $IMAGE_NAME variable to the the file's IMAGE_NAME value + export "$(grep IMAGE_NAME $file)" + # The image should be listed as active + openstack image list --property name="$IMAGE_NAME" | grep "active" + if [ $? -ne 0 ]; then + echo "ERROR: No matching image found for $IMAGE_NAME" + error=true + fi +done + +if [ "$error" = true ]; then + exit 1 +fi -- 2.16.6