|
| 1 | +/* |
| 2 | + * Copyright OpenSearch Contributors |
| 3 | + * SPDX-License-Identifier: Apache-2.0 |
| 4 | + * |
| 5 | + * The OpenSearch Contributors require contributions made to |
| 6 | + * this file be licensed under the Apache-2.0 license or a |
| 7 | + * compatible open source license. |
| 8 | + */ |
| 9 | + |
| 10 | +lib = library(identifier: 'jenkins@8.1.0', retriever: modernSCM([ |
| 11 | + $class: 'GitSCMSource', |
| 12 | + remote: 'https://github.com/opensearch-project/opensearch-build-libraries.git', |
| 13 | +])) |
| 14 | + |
| 15 | +def docker_images = [ |
| 16 | + 'tar': 'opensearchstaging/ci-runner:ci-runner-al2-opensearch-build-v1', |
| 17 | + 'rpm': 'opensearchstaging/ci-runner:ci-runner-almalinux8-systemd-base-integtest-v1', |
| 18 | + 'deb': 'opensearchstaging/ci-runner:ci-runner-ubuntu2004-systemd-base-integtest-v3', |
| 19 | + 'zip': 'opensearchstaging/ci-runner:ci-runner-windows2019-opensearch-build-v1', |
| 20 | +] |
| 21 | + |
| 22 | +def docker_args = [ |
| 23 | + 'tar': '-u 1000 --cpus 4 -m 16g', |
| 24 | + 'rpm': '--entrypoint=/usr/lib/systemd/systemd -u root --privileged -v /sys/fs/cgroup:/sys/fs/cgroup:rw --cgroupns=host --cpus 4 -m 16g', |
| 25 | + 'deb': '--entrypoint=/usr/lib/systemd/systemd -u root --privileged -v /sys/fs/cgroup:/sys/fs/cgroup:rw --cgroupns=host --cpus 4 -m 16g', |
| 26 | + 'zip': '-u ContainerAdministrator', |
| 27 | +] |
| 28 | + |
| 29 | +def agent_nodes = [ |
| 30 | + 'linux_x64': 'Jenkins-Agent-AL2023-X64-M54xlarge-Docker-Host', |
| 31 | + 'linux_arm64': 'Jenkins-Agent-AL2023-Arm64-M6g4xlarge-Docker-Host', |
| 32 | + 'windows_x64': 'Jenkins-Agent-Windows2019-X64-M54xlarge-Docker-Host', |
| 33 | +] |
| 34 | + |
| 35 | +pipeline { |
| 36 | + options { |
| 37 | + timeout(time: 2, unit: 'HOURS') |
| 38 | + } |
| 39 | + agent none |
| 40 | + environment { |
| 41 | + BUILD_MANIFEST = 'build-manifest.yml' |
| 42 | + BUILD_JOB_NAME = 'distribution-build-opensearch' |
| 43 | + ARTIFACT_BUCKET_NAME = credentials('jenkins-artifact-bucket-name') |
| 44 | + } |
| 45 | + parameters { |
| 46 | + string( |
| 47 | + name: 'TEST_MANIFEST', |
| 48 | + description: 'Test manifest under the manifests folder, e.g. 2.19.0/opensearch-2.19.0-test.yml.', |
| 49 | + trim: true |
| 50 | + ) |
| 51 | + string( |
| 52 | + name: 'BUILD_MANIFEST_URL', |
| 53 | + description: 'The build manifest URL for OpenSearch, e.g. "https://ci.opensearch.org/ci/dbc/distribution-build-opensearch/2.19.0/10545/linux/x64/tar/builds/opensearch/manifest.yml".', |
| 54 | + trim: true |
| 55 | + ) |
| 56 | + } |
| 57 | + stages { |
| 58 | + stage('verify-parameters') { |
| 59 | + agent { label agent_nodes['linux_x64'] } |
| 60 | + steps { |
| 61 | + script { |
| 62 | + if (TEST_MANIFEST == '' || !fileExists("manifests/${TEST_MANIFEST}")) { |
| 63 | + currentBuild.result = 'ABORTED' |
| 64 | + error("Smoke Tests failed to start. Test manifest was not provided or not found in manifests/${TEST_MANIFEST}.") |
| 65 | + } |
| 66 | + |
| 67 | + if (BUILD_MANIFEST_URL == '') { |
| 68 | + currentBuild.result = 'ABORTED' |
| 69 | + error('Smoke Tests failed to start. Build manifest url was not provided.') |
| 70 | + } |
| 71 | + downloadBuildManifest( |
| 72 | + url: BUILD_MANIFEST_URL, |
| 73 | + path: BUILD_MANIFEST |
| 74 | + ) |
| 75 | + |
| 76 | + def buildManifestObj = lib.jenkins.BuildManifest.new(readYaml(file: BUILD_MANIFEST)) |
| 77 | + env.architecture = buildManifestObj.getArtifactArchitecture() |
| 78 | + env.buildId = buildManifestObj.getArtifactBuildId() |
| 79 | + env.distribution = buildManifestObj.getDistribution() |
| 80 | + env.version = buildManifestObj.build.version |
| 81 | + env.platform = buildManifestObj.build.platform |
| 82 | + env.artifactPath = buildManifestObj.getArtifactRoot(BUILD_JOB_NAME, buildId) |
| 83 | + env.AGENT_LABEL = agent_nodes["${env.platform}_${architecture}"] |
| 84 | + } |
| 85 | + } |
| 86 | + post { |
| 87 | + always { |
| 88 | + postCleanup() |
| 89 | + } |
| 90 | + } |
| 91 | + } |
| 92 | + stage('smoke-test') { |
| 93 | + options { |
| 94 | + timeout(time: 1, unit: 'HOURS') |
| 95 | + } |
| 96 | + agent { |
| 97 | + docker { |
| 98 | + label AGENT_LABEL |
| 99 | + image docker_images[env.distribution] |
| 100 | + args docker_args[env.distribution] |
| 101 | + registryUrl 'https://public.ecr.aws/' |
| 102 | + alwaysPull true |
| 103 | + } |
| 104 | + } |
| 105 | + steps { |
| 106 | + script { |
| 107 | + currentBuild.description = "$TEST_MANIFEST, $version, $architecture, $platform, $buildId, $distribution" |
| 108 | + |
| 109 | + try { |
| 110 | + stage("Smoke_tests") { |
| 111 | + checkout scm |
| 112 | + sleep 10 |
| 113 | + downloadBuildManifest( |
| 114 | + url: BUILD_MANIFEST_URL, |
| 115 | + path: BUILD_MANIFEST |
| 116 | + ) |
| 117 | + |
| 118 | + def buildManifestObj = lib.jenkins.BuildManifest.new(readYaml(file: BUILD_MANIFEST)) |
| 119 | + def testManifestObj = lib.jenkins.TestManifest.new(readYaml(file: "manifests/${TEST_MANIFEST}")) |
| 120 | + |
| 121 | + sh('rm -rf test-results') |
| 122 | + runSmokeTestScript( |
| 123 | + jobName: "$BUILD_JOB_NAME", |
| 124 | + buildManifest: "$BUILD_MANIFEST", |
| 125 | + testManifest: "manifests/${TEST_MANIFEST}", |
| 126 | + buildId: "${buildId}" |
| 127 | + ) |
| 128 | + } |
| 129 | + } catch (e) { |
| 130 | + throw new Exception("Error running Smoke test", e) |
| 131 | + } finally { |
| 132 | + echo "Completed running smoke tests." |
| 133 | + postCleanup() |
| 134 | + } |
| 135 | + } |
| 136 | + } |
| 137 | + post { |
| 138 | + always { |
| 139 | + postCleanup() |
| 140 | + } |
| 141 | + } |
| 142 | + } |
| 143 | + } |
| 144 | + post { |
| 145 | + always { |
| 146 | + node(AGENT_LABEL) { |
| 147 | + script { |
| 148 | + postCleanup() |
| 149 | + } |
| 150 | + } |
| 151 | + } |
| 152 | + } |
| 153 | +} |
0 commit comments