|
1 | | -import java.text.SimpleDateFormat |
2 | | - |
3 | 1 | // 3 hours |
4 | | -def TIMEOUT = 10800 |
| 2 | +int timeout = 10800 |
5 | 3 |
|
6 | 4 | script { |
| 5 | + UPDATED_REPO = "https://github.com/${env.REPO_OWNER}/${env.REPO_NAME}.git" |
| 6 | + echo "Test triggered from ${UPDATED_REPO}" |
| 7 | + ci_git_url = 'https://github.com/metal3-io/project-infra.git' |
7 | 8 |
|
8 | | - UPDATED_REPO = "https://github.com/${env.REPO_OWNER}/${env.REPO_NAME}.git" |
9 | | - echo "Test triggered from ${UPDATED_REPO}" |
10 | | - ci_git_url = "https://github.com/metal3-io/project-infra.git" |
11 | | - |
12 | | - if ("${env.REPO_OWNER}" == 'metal3-io' && "${env.REPO_NAME}" == 'project-infra') { |
13 | | - ci_git_branch = (env.PULL_PULL_SHA) ?: 'main' |
14 | | - ci_git_base = (env.PULL_BASE_REF) ?: 'main' |
15 | | - // Fetch the base branch and the ci_git_branch when running on project-infra PR |
16 | | - refspec = '+refs/heads/' + ci_git_base + ':refs/remotes/origin/' + ci_git_base + ' ' + ci_git_branch |
| 9 | + if ("${env.REPO_OWNER}" == 'metal3-io' && "${env.REPO_NAME}" == 'project-infra') { |
| 10 | + ci_git_branch = (env.PULL_PULL_SHA) ?: 'main' |
| 11 | + ci_git_base = (env.PULL_BASE_REF) ?: 'main' |
| 12 | + // Fetch the base branch and the ci_git_branch when running on project-infra PR |
| 13 | + refspec = '+refs/heads/' + ci_git_base + ':refs/remotes/origin/' + ci_git_base + ' ' + ci_git_branch |
17 | 14 | } else { |
18 | | - ci_git_branch = 'main' |
19 | | - refspec = '+refs/heads/*:refs/remotes/origin/*' |
20 | | - } |
| 15 | + ci_git_branch = 'main' |
| 16 | + refspec = '+refs/heads/*:refs/remotes/origin/*' |
| 17 | + } |
21 | 18 | echo "Checkout ${ci_git_url} branch ${ci_git_branch}" |
22 | 19 | } |
23 | 20 |
|
24 | 21 | pipeline { |
25 | 22 | /* In the BML we always run on the same machine so concurrency must be disabled */ |
26 | | - options { |
27 | | - disableConcurrentBuilds() |
28 | | - } |
29 | | - agent { label 'metal3ci-bml-jenkins-worker' } |
30 | | - environment { |
31 | | - METAL3_CI_USER="metal3ci" |
32 | | - REPO_ORG = "${env.REPO_OWNER}" |
33 | | - REPO_NAME = "${env.REPO_NAME}" |
34 | | - UPDATED_REPO = "${UPDATED_REPO}" |
35 | | - REPO_BRANCH = "${env.PULL_BASE_REF}" |
36 | | - UPDATED_BRANCH = "${env.PULL_PULL_SHA}" |
37 | | - BUILD_TAG = "${env.BUILD_TAG}" |
38 | | - PR_ID = "${env.PULL_NUMBER}" |
39 | | - IMAGE_OS = "${IMAGE_OS}" |
40 | | - CAPM3RELEASEBRANCH = "${capm3_release_branch}" |
41 | | - BMORELEASEBRANCH = "${bmo_release_branch}" |
42 | | - NUM_NODES = "${NUM_NODES}" |
43 | | - WORKER_MACHINE_COUNT = 1 |
44 | | - CONTROL_PLANE_MACHINE_COUNT = 1 |
45 | | - CAPI_VERSION = "${CAPI_VERSION}" |
46 | | - CAPM3_VERSION = "${CAPM3_VERSION}" |
47 | | - BOOTSTRAP_CLUSTER = "minikube" |
48 | | - EXTERNAL_VLAN_ID = "3" |
49 | | - } |
50 | | - stages { |
51 | | - stage('SCM') { |
52 | | - options { |
53 | | - timeout(time: 5, unit: 'MINUTES') |
54 | | - } |
55 | | - steps { |
56 | | - /* Checkout CI Repo */ |
57 | | - checkout([ |
58 | | - $class: 'GitSCM', |
59 | | - branches: [ |
60 | | - [name: ci_git_branch] |
61 | | - ], |
62 | | - doGenerateSubmoduleConfigurations: false, |
63 | | - extensions: [ |
64 | | - [$class: 'WipeWorkspace'], |
65 | | - [$class: 'CleanCheckout'], |
66 | | - [$class: 'CleanBeforeCheckout'] |
67 | | - ], |
68 | | - submoduleCfg: [], |
69 | | - userRemoteConfigs: [[url: ci_git_url, refspec: refspec]] |
70 | | - ]) |
71 | | - script { |
72 | | - CURRENT_START_TIME = System.currentTimeMillis() |
73 | | - } |
74 | | - } |
| 23 | + options { |
| 24 | + disableConcurrentBuilds() |
75 | 25 | } |
76 | | - stage('Run integration test') { |
77 | | - options { |
78 | | - timeout(time: TIMEOUT, unit: 'SECONDS') |
79 | | - } |
80 | | - steps { |
81 | | - withCredentials([sshUserPrivateKey(credentialsId: 'metal3ci_city_cloud_ssh_keypair', keyFileVariable: 'METAL3_CI_USER_KEY')]) { |
82 | | - withCredentials([usernamePassword(credentialsId: 'metal3-bml-ilo-credentials', usernameVariable: 'BML_ILO_USERNAME', passwordVariable: 'BML_ILO_PASSWORD')]) { |
83 | | - withCredentials([string(credentialsId: 'metal3-clusterctl-github-token', variable: 'GITHUB_TOKEN')]){ |
84 | | - timestamps { |
85 | | - sh "./jenkins/scripts/bare_metal_lab/bml_integration_test.sh" |
86 | | - } |
| 26 | + agent { label 'metal3ci-bml-jenkins-worker' } |
| 27 | + environment { |
| 28 | + METAL3_CI_USER = 'metal3ci' |
| 29 | + REPO_ORG = "${env.REPO_OWNER}" |
| 30 | + REPO_NAME = "${env.REPO_NAME}" |
| 31 | + UPDATED_REPO = "${UPDATED_REPO}" |
| 32 | + REPO_BRANCH = "${env.PULL_BASE_REF}" |
| 33 | + UPDATED_BRANCH = "${env.PULL_PULL_SHA}" |
| 34 | + BUILD_TAG = "${env.BUILD_TAG}" |
| 35 | + PR_ID = "${env.PULL_NUMBER}" |
| 36 | + IMAGE_OS = "${IMAGE_OS}" |
| 37 | + CAPM3RELEASEBRANCH = "${capm3_release_branch}" |
| 38 | + BMORELEASEBRANCH = "${bmo_release_branch}" |
| 39 | + NUM_NODES = "${NUM_NODES}" |
| 40 | + WORKER_MACHINE_COUNT = 1 |
| 41 | + CONTROL_PLANE_MACHINE_COUNT = 1 |
| 42 | + CAPI_VERSION = "${CAPI_VERSION}" |
| 43 | + CAPM3_VERSION = "${CAPM3_VERSION}" |
| 44 | + EPHEMERAL_CLUSTER = 'minikube' |
| 45 | + EXTERNAL_VLAN_ID = '3' |
| 46 | + } |
| 47 | + stages { |
| 48 | + stage('SCM') { ; |
| 49 | + options { |
| 50 | + timeout(time: 5, unit: 'MINUTES') |
| 51 | + } |
| 52 | + steps { |
| 53 | + /* Checkout CI Repo */ |
| 54 | + checkout([ |
| 55 | + $class: 'GitSCM', |
| 56 | + branches: [ |
| 57 | + [name: ci_git_branch] |
| 58 | + ], |
| 59 | + doGenerateSubmoduleConfigurations: false, |
| 60 | + extensions: [ |
| 61 | + [$class: 'WipeWorkspace'], |
| 62 | + [$class: 'CleanCheckout'], |
| 63 | + [$class: 'CleanBeforeCheckout'] |
| 64 | + ], |
| 65 | + submoduleCfg: [], |
| 66 | + userRemoteConfigs: [[url: ci_git_url, refspec: refspec]] |
| 67 | + ]) |
| 68 | + script { |
| 69 | + CURRENT_START_TIME = System.currentTimeMillis() |
| 70 | + } |
87 | 71 | } |
88 | | - } |
89 | 72 | } |
90 | | - } |
91 | | - } |
92 | | - } |
93 | | - post { |
94 | | - always { |
95 | | - script { |
96 | | - CURRENT_END_TIME = System.currentTimeMillis() |
97 | | - if ((((CURRENT_END_TIME - CURRENT_START_TIME)/1000) - TIMEOUT) > 0) { |
98 | | - echo "Failed due to timeout" |
99 | | - currentBuild.result = 'FAILURE' |
| 73 | + stage('Run integration test') { |
| 74 | + options { |
| 75 | + timeout(time: timeout, unit: 'SECONDS') |
| 76 | + } |
| 77 | + steps { |
| 78 | + withCredentials([ |
| 79 | + sshUserPrivateKey(credentialsId: 'metal3ci_city_cloud_ssh_keypair', keyFileVariable: 'METAL3_CI_USER_KEY'), |
| 80 | + usernamePassword(credentialsId: 'metal3-bml-ilo-credentials', usernameVariable: 'BML_ILO_USERNAME', passwordVariable: 'BML_ILO_PASSWORD'), |
| 81 | + string(credentialsId: 'metal3-clusterctl-github-token', variable: 'GITHUB_TOKEN')]) { |
| 82 | + timestamps { |
| 83 | + sh './jenkins/scripts/bare_metal_lab/bml_integration_test.sh' |
| 84 | + } |
| 85 | + } |
| 86 | + } |
100 | 87 | } |
101 | | - } |
102 | | - withCredentials([sshUserPrivateKey(credentialsId: 'metal3ci_city_cloud_ssh_keypair', keyFileVariable: 'METAL3_CI_USER_KEY')]){ |
103 | | - withCredentials([usernamePassword(credentialsId: 'metal3-bml-ilo-credentials', usernameVariable: 'BML_ILO_USERNAME', passwordVariable: 'BML_ILO_PASSWORD')]) { |
104 | | - timestamps { |
105 | | - sh "./jenkins/scripts/dynamic_worker_workflow/fetch_logs.sh" |
| 88 | + } |
| 89 | + post { |
| 90 | + always { |
| 91 | + script { |
| 92 | + CURRENT_END_TIME = System.currentTimeMillis() |
| 93 | + if ((((CURRENT_END_TIME - CURRENT_START_TIME) / 1000) - timeout) > 0) { |
| 94 | + echo 'Failed due to timeout' |
| 95 | + currentBuild.result = 'FAILURE' |
| 96 | + } |
| 97 | + } |
| 98 | + withCredentials([sshUserPrivateKey(credentialsId: 'metal3ci_city_cloud_ssh_keypair', keyFileVariable: 'METAL3_CI_USER_KEY'), |
| 99 | + usernamePassword(credentialsId: 'metal3-bml-ilo-credentials', usernameVariable: 'BML_ILO_USERNAME', passwordVariable: 'BML_ILO_PASSWORD')]) { |
| 100 | + timestamps { |
| 101 | + sh './jenkins/scripts/dynamic_worker_workflow/fetch_logs.sh' |
| 102 | + archiveArtifacts "logs-${env.BUILD_TAG}.tgz" |
| 103 | + } |
| 104 | + } |
106 | 105 | archiveArtifacts "logs-${env.BUILD_TAG}.tgz" |
107 | | - } |
108 | 106 | } |
109 | | - } |
110 | | - archiveArtifacts "logs-${env.BUILD_TAG}.tgz" |
111 | | - } |
112 | | - success { |
113 | | - withCredentials([sshUserPrivateKey(credentialsId: 'metal3ci_city_cloud_ssh_keypair', keyFileVariable: 'METAL3_CI_USER_KEY')]){ |
114 | | - withCredentials([usernamePassword(credentialsId: 'metal3-bml-ilo-credentials', usernameVariable: 'BML_ILO_USERNAME', passwordVariable: 'BML_ILO_PASSWORD')]) { |
115 | | - withCredentials([string(credentialsId: 'metal3-clusterctl-github-token', variable: 'GITHUB_TOKEN')]){ |
116 | | - timestamps { |
117 | | - sh "./jenkins/scripts/bare_metal_lab/bml_cleanup.sh" |
| 107 | + success { |
| 108 | + withCredentials([sshUserPrivateKey(credentialsId: 'metal3ci_city_cloud_ssh_keypair', keyFileVariable: 'METAL3_CI_USER_KEY'), |
| 109 | + usernamePassword(credentialsId: 'metal3-bml-ilo-credentials', usernameVariable: 'BML_ILO_USERNAME', passwordVariable: 'BML_ILO_PASSWORD'), |
| 110 | + string(credentialsId: 'metal3-clusterctl-github-token', variable: 'GITHUB_TOKEN')]) { |
| 111 | + timestamps { |
| 112 | + sh './jenkins/scripts/bare_metal_lab/bml_cleanup.sh' |
| 113 | + } |
118 | 114 | } |
119 | | - } |
120 | 115 | } |
121 | | - } |
122 | 116 | } |
123 | | - } |
124 | 117 | } |
0 commit comments