|
| 1 | +#!groovy |
| 2 | + |
| 3 | +// See 'Loading libraries dynamically' here: https://jenkins.io/doc/book/pipeline/shared-libraries/ |
| 4 | +library 'cdis-jenkins-lib@master' |
| 5 | + |
| 6 | +node { |
| 7 | + def AVAILABLE_NAMESPACES = ['jenkins-blood', 'jenkins-brain', 'jenkins-niaid', 'jenkins-dcp', 'jenkins-genomel'] |
| 8 | + List<String> namespaces = [] |
| 9 | + List<String> listOfSelectedTests = [] |
| 10 | + doNotRunTests = false |
| 11 | + kubectlNamespace = null |
| 12 | + kubeLocks = [] |
| 13 | + testedEnv = "" // for manifest pipeline |
| 14 | + pipeConfig = pipelineHelper.setupConfig([:]) |
| 15 | + pipelineHelper.cancelPreviousRunningBuilds() |
| 16 | + prLabels = githubHelper.fetchLabels() |
| 17 | + |
| 18 | + try { |
| 19 | + stage('CleanWorkspace') { |
| 20 | + cleanWs() |
| 21 | + } |
| 22 | + stage('FetchCode'){ |
| 23 | + gitHelper.fetchAllRepos(pipeConfig['currentRepoName']) |
| 24 | + sh 'ls && test -f ./tmpGitClone/tests/jenkinsSmoke.sh' |
| 25 | + } |
| 26 | + stage('CheckPRLabels') { |
| 27 | + // giving a chance for auto-label gh actions to catch up |
| 28 | + // sleep(10) |
| 29 | + for(label in prLabels) { |
| 30 | + println(label['name']); |
| 31 | + switch(label['name']) { |
| 32 | + case "doc-only": |
| 33 | + println('Skip tests if git diff matches expected criteria') |
| 34 | + doNotRunTests = docOnlyHelper.checkTestSkippingCriteria() |
| 35 | + break |
| 36 | + case "not-ready-for-ci": |
| 37 | + currentBuild.result = 'ABORTED' |
| 38 | + error('This PR is not ready for CI yet, aborting...') |
| 39 | + break |
| 40 | + case AVAILABLE_NAMESPACES: |
| 41 | + println('found this namespace label! ' + label['name']); |
| 42 | + namespaces.add(label['name']) |
| 43 | + break |
| 44 | + case "qaplanetv2": |
| 45 | + println('This PR check will run in a qaplanetv2 environment! '); |
| 46 | + namespaces.add('ci-env-1') |
| 47 | + break |
| 48 | + default: |
| 49 | + println('no-effect label') |
| 50 | + break |
| 51 | + } |
| 52 | + } |
| 53 | + // If none of the jenkins envs. have been selected pick one at random |
| 54 | + if (namespaces.isEmpty()) { |
| 55 | + println('populating namespaces with list of available namespaces...') |
| 56 | + namespaces = AVAILABLE_NAMESPACES |
| 57 | + } |
| 58 | + } |
| 59 | + stage('SelectNamespace') { |
| 60 | + if(!doNotRunTests) { |
| 61 | + (kubectlNamespace, lock) = kubeHelper.selectAndLockNamespace(pipeConfig['UID'], namespaces) |
| 62 | + kubeLocks << lock |
| 63 | + } else { |
| 64 | + Utils.markStageSkippedForConditional(STAGE_NAME) |
| 65 | + } |
| 66 | + } |
| 67 | + stage('K8sReset') { |
| 68 | + if(!doNotRunTests) { |
| 69 | + // adding the reset-lock lock in case reset fails before unlocking |
| 70 | + kubeLocks << kubeHelper.newKubeLock(kubectlNamespace, "gen3-reset", "reset-lock") |
| 71 | + kubeHelper.reset(kubectlNamespace) |
| 72 | + } else { |
| 73 | + Utils.markStageSkippedForConditional(STAGE_NAME) |
| 74 | + } |
| 75 | + } |
| 76 | + stage('VerifyClusterHealth') { |
| 77 | + if(!doNotRunTests) { |
| 78 | + kubeHelper.waitForPods(kubectlNamespace) |
| 79 | + testHelper.checkPodHealth(kubectlNamespace, "") |
| 80 | + } else { |
| 81 | + Utils.markStageSkippedForConditional(STAGE_NAME) |
| 82 | + } |
| 83 | + } |
| 84 | + stage('SmokeTest') { |
| 85 | + if(!doNotRunTests) { |
| 86 | + kubeHelper.kube(kubectlNamespace, { |
| 87 | + sh 'bash ./tmpGitClone/tests/jenkinsSmoke.sh' |
| 88 | + }) |
| 89 | + } else { |
| 90 | + Utils.markStageSkippedForConditional(STAGE_NAME) |
| 91 | + } |
| 92 | + } |
| 93 | + } catch (e) { |
| 94 | + pipelineHelper.handleError(e) |
| 95 | + } |
| 96 | + finally { |
| 97 | + stage('Post') { |
| 98 | + kubeHelper.teardown(kubeLocks) |
| 99 | + // tear down network policies deployed by the tests |
| 100 | + kubeHelper.kube(kubectlNamespace, { |
| 101 | + sh(script: 'kubectl --namespace="' + kubectlNamespace + '" delete networkpolicies --all', returnStatus: true); |
| 102 | + }); |
| 103 | + pipelineHelper.teardown(currentBuild.result) |
| 104 | + } |
| 105 | + } |
| 106 | +} |
0 commit comments