Verify jenkins-config files have matching images 83/13283/8
authorEric Ball <eball@linuxfoundation.org>
Thu, 25 Oct 2018 21:54:32 +0000 (14:54 -0700)
committerThanh Ha <thanh.ha@linuxfoundation.org>
Tue, 6 Nov 2018 02:45:57 +0000 (10:45 +0800)
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 <eball@linuxfoundation.org>
.jjb-test/lf-ci-jobs/jenkins-cfg-verify.yaml [new file with mode: 0644]
docs/jjb/lf-ci-jobs.rst
jjb/lf-ci-jobs.yaml
shell/jenkins-verify-images.sh [new file with mode: 0755]

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 (file)
index 0000000..124b943
--- /dev/null
@@ -0,0 +1,7 @@
+---
+- project:
+    name: jenkins-cfg-verify
+    jobs:
+      - "gerrit-jenkins-cfg-verify"
+
+    project-name: ci-management
index a394741..8c0ad44 100644 (file)
@@ -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
 -----------------------
index 638716e..da70ba3 100644 (file)
           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 (executable)
index 0000000..aed8d12
--- /dev/null
@@ -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