1 /* Copyright ETSI Contributors and Others
5 * Licensed under the Apache License, Version 2.0 (the "License"); you may
6 * not use this file except in compliance with the License. You may obtain
7 * a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14 * License for the specific language governing permissions and limitations
20 string(defaultValue: env.GERRIT_BRANCH, description: '', name: 'GERRIT_BRANCH'),
21 string(defaultValue: 'system', description: '', name: 'NODE'),
22 string(defaultValue: '', description: '', name: 'BUILD_FROM_SOURCE'),
23 string(defaultValue: 'unstable', description: '', name: 'REPO_DISTRO'),
24 string(defaultValue: '', description: '', name: 'COMMIT_ID'),
25 string(defaultValue: '-stage_2', description: '', name: 'UPSTREAM_SUFFIX'),
26 string(defaultValue: 'pubkey.asc', description: '', name: 'REPO_KEY_NAME'),
27 string(defaultValue: 'release', description: '', name: 'RELEASE'),
28 string(defaultValue: '', description: '', name: 'UPSTREAM_JOB_NAME'),
29 string(defaultValue: '', description: '', name: 'UPSTREAM_JOB_NUMBER'),
30 string(defaultValue: 'OSMETSI', description: '', name: 'GPG_KEY_NAME'),
31 string(defaultValue: 'artifactory-osm', description: '', name: 'ARTIFACTORY_SERVER'),
32 string(defaultValue: 'osm-stage_4', description: '', name: 'DOWNSTREAM_STAGE_NAME'),
33 string(defaultValue: 'testing-daily', description: '', name: 'DOCKER_TAG'),
34 string(defaultValue: 'ubuntu20.04', description: '', name: 'OPENSTACK_BASE_IMAGE'),
35 booleanParam(defaultValue: false, description: '', name: 'SAVE_CONTAINER_ON_FAIL'),
36 booleanParam(defaultValue: false, description: '', name: 'SAVE_CONTAINER_ON_PASS'),
37 booleanParam(defaultValue: true, description: '', name: 'SAVE_ARTIFACTS_ON_SMOKE_SUCCESS'),
38 booleanParam(defaultValue: true, description: '', name: 'DO_BUILD'),
39 booleanParam(defaultValue: true, description: '', name: 'DO_INSTALL'),
40 booleanParam(defaultValue: true, description: '', name: 'DO_DOCKERPUSH'),
41 booleanParam(defaultValue: false, description: '', name: 'SAVE_ARTIFACTS_OVERRIDE'),
42 string(defaultValue: '/home/jenkins/hive/openstack-etsi.rc', description: '', name: 'HIVE_VIM_1'),
43 booleanParam(defaultValue: true, description: '', name: 'DO_ROBOT'),
44 string(defaultValue: 'sanity', description: 'sanity/regression/daily are the common options',
45 name: 'ROBOT_TAG_NAME'),
46 string(defaultValue: '/home/jenkins/hive/robot-systest.cfg', description: '', name: 'ROBOT_VIM'),
47 string(defaultValue: '/home/jenkins/hive/port-mapping-etsi-vim.yaml',
48 description: 'Port mapping file for SDN assist in ETSI VIM',
49 name: 'ROBOT_PORT_MAPPING_VIM'),
50 string(defaultValue: '/home/jenkins/hive/kubeconfig.yaml', description: '', name: 'KUBECONFIG'),
51 string(defaultValue: '/home/jenkins/hive/clouds.yaml', description: '', name: 'CLOUDS'),
52 string(defaultValue: 'Default', description: '', name: 'INSTALLER'),
53 string(defaultValue: '100.0', description: '% passed Robot tests to mark the build as passed',
54 name: 'ROBOT_PASS_THRESHOLD'),
55 string(defaultValue: '80.0', description: '% passed Robot tests to mark the build as unstable ' +
56 '(if lower, it will be failed)', name: 'ROBOT_UNSTABLE_THRESHOLD'),
60 ////////////////////////////////////////////////////////////////////////////////////////
62 ////////////////////////////////////////////////////////////////////////////////////////
63 void run_robot_systest(String tagName,
66 String prometheusHostname,
67 Integer prometheusPort=null,
69 String portmappingfile=null,
70 String kubeconfig=null,
73 String jujuPassword=null,
74 String osmRSAfile=null,
75 String passThreshold='0.0',
76 String unstableThreshold='0.0') {
77 tempdir = sh(returnStdout: true, script: 'mktemp -d').trim()
78 String environmentFile = ''
80 environmentFile = envfile
82 sh(script: "touch ${tempdir}/env")
83 environmentFile = "${tempdir}/env"
85 PROMETHEUS_PORT_VAR = ''
86 if (prometheusPort != null) {
87 PROMETHEUS_PORT_VAR = "--env PROMETHEUS_PORT=${prometheusPort}"
91 hostfilemount = "-v ${hostfile}:/etc/hosts"
94 JUJU_PASSWORD_VAR = ''
95 if (jujuPassword != null) {
96 JUJU_PASSWORD_VAR = "--env JUJU_PASSWORD=${jujuPassword}"
100 sh("""docker run --env OSM_HOSTNAME=${osmHostname} --env PROMETHEUS_HOSTNAME=${prometheusHostname} \
101 ${PROMETHEUS_PORT_VAR} ${JUJU_PASSWORD_VAR} --env-file ${environmentFile} \
102 -v ${clouds}:/etc/openstack/clouds.yaml \
103 -v ${osmRSAfile}:/root/osm_id_rsa -v ${kubeconfig}:/root/.kube/config -v ${tempdir}:/robot-systest/reports \
104 -v ${portmappingfile}:/root/port-mapping.yaml ${hostfilemount} opensourcemano/tests:${tagName} \
105 -c -t ${testName}""")
107 sh("cp ${tempdir}/* .")
108 outputDirectory = sh(returnStdout: true, script: 'pwd').trim()
109 println("Present Directory is : ${outputDirectory}")
111 $class : 'RobotPublisher',
112 outputPath : "${outputDirectory}",
113 outputFileName : '*.xml',
114 disableArchiveOutput : false,
115 reportFileName : 'report.html',
116 logFileName : 'log.html',
117 passThreshold : passThreshold,
118 unstableThreshold: unstableThreshold,
119 otherFiles : '*.png',
124 void archive_logs(Map remote) {
126 sshCommand remote: remote, command: '''mkdir -p logs'''
127 if (useCharmedInstaller) {
128 sshCommand remote: remote, command: '''
129 for container in `kubectl get pods -n osm | grep -v operator | grep -v NAME| awk '{print $1}'`; do
130 logfile=`echo $container | cut -d- -f1`
131 echo "Extracting log for $logfile"
132 kubectl logs -n osm $container --timestamps=true 2>&1 > logs/$logfile.log
136 sshCommand remote: remote, command: '''
137 for deployment in `kubectl -n osm get deployments | grep -v operator | grep -v NAME| awk '{print $1}'`; do
138 echo "Extracting log for $deployment"
139 kubectl -n osm logs deployments/$deployment --timestamps=true --all-containers 2>&1 \
140 > logs/$deployment.log
143 sshCommand remote: remote, command: '''
144 for statefulset in `kubectl -n osm get statefulsets | grep -v operator | grep -v NAME| awk '{print $1}'`; do
145 echo "Extracting log for $statefulset"
146 kubectl -n osm logs statefulsets/$statefulset --timestamps=true --all-containers 2>&1 \
147 > logs/$statefulset.log
153 sshCommand remote: remote, command: '''ls -al logs'''
154 sshGet remote: remote, from: 'logs', into: '.', override: true
156 archiveArtifacts artifacts: '*.log'
159 String get_value(String key, String output) {
160 for (String line : output.split( '\n' )) {
161 data = line.split( '\\|' )
162 if (data.length > 1) {
163 if ( data[1].trim() == key ) {
164 return data[2].trim()
170 ////////////////////////////////////////////////////////////////////////////////////////
172 ////////////////////////////////////////////////////////////////////////////////////////
173 node("${params.NODE}") {
175 INTERNAL_DOCKER_REGISTRY = 'osm.etsi.org:5050/devops/cicd/'
176 INTERNAL_DOCKER_PROXY = 'http://172.21.1.1:5000'
177 APT_PROXY = 'http://172.21.1.1:3142'
178 SSH_KEY = '~/hive/cicd_rsa'
179 ARCHIVE_LOGS_FLAG = false
182 tag_or_branch = params.GERRIT_BRANCH.replaceAll(/\./, '')
188 ci_helper = load 'jenkins/ci-pipelines/ci_helper.groovy'
190 def upstreamMainJob = params.UPSTREAM_SUFFIX
192 // upstream jobs always use merged artifacts
193 upstreamMainJob += '-merge'
194 containerNamePrefix = "osm-${tag_or_branch}"
195 containerName = "${containerNamePrefix}"
197 keep_artifacts = false
198 if ( JOB_NAME.contains('merge') ) {
199 containerName += '-merge'
201 // On a merge job, we keep artifacts on smoke success
202 keep_artifacts = params.SAVE_ARTIFACTS_ON_SMOKE_SUCCESS
204 containerName += "-${BUILD_NUMBER}"
207 http_server_name = null
209 useCharmedInstaller = params.INSTALLER.equalsIgnoreCase('charmed')
213 ///////////////////////////////////////////////////////////////////////////////////////
214 // Fetch stage 2 .deb artifacts
215 ///////////////////////////////////////////////////////////////////////////////////////
216 stage('Copy Artifacts') {
217 // cleanup any previous repo
225 RELEASE_DIR = sh(returnStdout:true, script: 'pwd').trim()
227 // check if an upstream artifact based on specific build number has been requested
228 // This is the case of a merge build and the upstream merge build is not yet complete
229 // (it is not deemed a successful build yet). The upstream job is calling this downstream
230 // job (with the its build artifact)
231 def upstreamComponent = ''
232 if (params.UPSTREAM_JOB_NAME) {
233 println("Fetching upstream job artifact from ${params.UPSTREAM_JOB_NAME}")
234 lock('Artifactory') {
235 step ([$class: 'CopyArtifact',
236 projectName: "${params.UPSTREAM_JOB_NAME}",
237 selector: [$class: 'SpecificBuildSelector',
238 buildNumber: "${params.UPSTREAM_JOB_NUMBER}"]
241 upstreamComponent = ci_helper.get_mdg_from_project(
242 ci_helper.get_env_value('build.env','GERRIT_PROJECT'))
243 def buildNumber = ci_helper.get_env_value('build.env','BUILD_NUMBER')
244 dir("$upstreamComponent") {
245 // the upstream job name contains suffix with the project. Need this stripped off
246 project_without_branch = params.UPSTREAM_JOB_NAME.split('/')[0]
247 packages = ci_helper.get_archive(params.ARTIFACTORY_SERVER,
250 "${project_without_branch} :: ${GERRIT_BRANCH}",
253 packageList.addAll(packages)
254 println("Fetched pre-merge ${params.UPSTREAM_JOB_NAME}: ${packages}")
256 } // lock artifactory
260 list = ['RO', 'osmclient', 'IM', 'devops', 'MON', 'N2VC', 'NBI',
261 'common', 'LCM', 'POL', 'NG-UI', 'PLA', 'tests']
262 if (upstreamComponent.length() > 0) {
263 println("Skipping upstream fetch of ${upstreamComponent}")
264 list.remove(upstreamComponent)
266 for (buildStep in list) {
267 def component = buildStep
268 parallelSteps[component] = {
270 println("Fetching artifact for ${component}")
271 step([$class: 'CopyArtifact',
272 projectName: "${component}${upstreamMainJob}/${GERRIT_BRANCH}"])
274 // grab the archives from the stage_2 builds
275 // (ie. this will be the artifacts stored based on a merge)
276 packages = ci_helper.get_archive(params.ARTIFACTORY_SERVER,
279 "${component}${upstreamMainJob} :: ${GERRIT_BRANCH}",
280 ci_helper.get_env_value('build.env', 'BUILD_NUMBER'))
281 packageList.addAll(packages)
282 println("Fetched ${component}: ${packages}")
287 lock('Artifactory') {
288 parallel parallelSteps
291 ///////////////////////////////////////////////////////////////////////////////////////
292 // Create Devops APT repository
293 ///////////////////////////////////////////////////////////////////////////////////////
295 for (component in [ 'devops', 'IM', 'osmclient' ]) {
296 sh "ls -al ${component}/pool/"
297 sh "cp -r ${component}/pool/* pool/"
298 sh "dpkg-sig --sign builder -k ${GPG_KEY_NAME} pool/${component}/*"
299 sh "mkdir -p dists/${params.REPO_DISTRO}/${component}/binary-amd64/"
300 sh("""apt-ftparchive packages pool/${component} \
301 > dists/${params.REPO_DISTRO}/${component}/binary-amd64/Packages""")
302 sh "gzip -9fk dists/${params.REPO_DISTRO}/${component}/binary-amd64/Packages"
305 // create and sign the release file
306 sh "apt-ftparchive release dists/${params.REPO_DISTRO} > dists/${params.REPO_DISTRO}/Release"
307 sh("""gpg --yes -abs -u ${GPG_KEY_NAME} \
308 -o dists/${params.REPO_DISTRO}/Release.gpg dists/${params.REPO_DISTRO}/Release""")
310 // copy the public key into the release folder
311 // this pulls the key from the home dir of the current user (jenkins)
312 sh "cp ~/${REPO_KEY_NAME} 'OSM ETSI Release Key.gpg'"
313 sh "cp ~/${REPO_KEY_NAME} ."
316 // start an apache server to serve up the packages
317 http_server_name = "${containerName}-apache"
319 pwd = sh(returnStdout:true, script: 'pwd').trim()
320 repo_port = sh(script: 'echo $(python -c \'import socket; s=socket.socket(); s.bind(("", 0));' +
321 'print(s.getsockname()[1]); s.close()\');',
322 returnStdout: true).trim()
323 internal_docker_http_server_url = ci_helper.start_http_server(pwd, http_server_name, repo_port)
324 NODE_IP_ADDRESS = sh(returnStdout: true, script:
325 "echo ${SSH_CONNECTION} | awk '{print \$3}'").trim()
326 ci_helper.check_status_http_server(NODE_IP_ADDRESS, repo_port)
329 // Unpack devops package into temporary location so that we use it from upstream if it was part of a patch
330 osm_devops_dpkg = sh(returnStdout: true, script: 'find ./repo/release/pool/ -name osm-devops*.deb').trim()
331 devopstempdir = sh(returnStdout: true, script: 'mktemp -d').trim()
332 println("Extracting local devops package ${osm_devops_dpkg} into ${devopstempdir} for docker build step")
333 sh "dpkg -x ${osm_devops_dpkg} ${devopstempdir}"
334 OSM_DEVOPS = "${devopstempdir}/usr/share/osm-devops"
335 // Convert URLs from stage 2 packages to arguments that can be passed to docker build
336 for (remotePath in packageList) {
337 packageName = remotePath[remotePath.lastIndexOf('/') + 1 .. -1]
338 packageName = packageName[0 .. packageName.indexOf('_') - 1]
339 builtModules[packageName] = remotePath
343 ///////////////////////////////////////////////////////////////////////////////////////
344 // Build docker containers
345 ///////////////////////////////////////////////////////////////////////////////////////
349 if ( params.DO_BUILD ) {
350 withCredentials([[$class: 'UsernamePasswordMultiBinding', credentialsId: 'gitlab-registry',
351 usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD']]) {
352 sh "docker login ${INTERNAL_DOCKER_REGISTRY} -u ${USERNAME} -p ${PASSWORD}"
354 datetime = sh(returnStdout: true, script: 'date +%Y-%m-%d:%H:%M:%S').trim()
355 moduleBuildArgs = " --build-arg CACHE_DATE=${datetime}"
356 for (packageName in builtModules.keySet()) {
357 envName = packageName.replaceAll('-', '_').toUpperCase() + '_URL'
358 moduleBuildArgs += " --build-arg ${envName}=" + builtModules[packageName]
362 containerList = sh(returnStdout: true, script:
363 "find . -name Dockerfile -printf '%h\\n' | sed 's|\\./||'")
364 containerList = Arrays.asList(containerList.split('\n'))
367 for (buildStep in containerList) {
368 def module = buildStep
369 def moduleName = buildStep.toLowerCase()
370 def moduleTag = containerName
371 parallelSteps[module] = {
373 sh("""docker build --build-arg APT_PROXY=${APT_PROXY} \
374 -t opensourcemano/${moduleName}:${moduleTag} ${moduleBuildArgs} .""")
375 println("Tagging ${moduleName}:${moduleTag}")
376 sh("""docker tag opensourcemano/${moduleName}:${moduleTag} \
377 ${INTERNAL_DOCKER_REGISTRY}opensourcemano/${moduleName}:${moduleTag}""")
379 ${INTERNAL_DOCKER_REGISTRY}opensourcemano/${moduleName}:${moduleTag}""")
383 parallel parallelSteps
386 } // if (params.DO_BUILD)
388 if (params.DO_INSTALL) {
389 ///////////////////////////////////////////////////////////////////////////////////////
391 ///////////////////////////////////////////////////////////////////////////////////////
392 stage('Spawn Remote VM') {
393 println('Launching new VM')
394 output = sh(returnStdout: true, script: """#!/bin/sh -e
395 for line in `grep OS ~/hive/robot-systest.cfg | grep -v OS_CLOUD` ; do export \$line ; done
396 openstack server create --flavor osm.sanity \
397 --image ${OPENSTACK_BASE_IMAGE} \
399 --property build_url="${BUILD_URL}" \
400 --nic net-id=osm-ext \
404 server_id = get_value('id', output)
406 if (server_id == null) {
407 println('VM launch output: ')
409 throw new Exception('VM Launch failed')
411 println("Target VM is ${server_id}, waiting for IP address to be assigned")
415 while (IP_ADDRESS == '') {
416 output = sh(returnStdout: true, script: """#!/bin/sh -e
417 for line in `grep OS ~/hive/robot-systest.cfg | grep -v OS_CLOUD` ; do export \$line ; done
418 openstack server show ${server_id}
420 IP_ADDRESS = get_value('addresses', output)
422 IP_ADDRESS = IP_ADDRESS.split('=')[1]
423 println("Waiting for VM at ${IP_ADDRESS} to be reachable")
426 timeout(time: 1, unit: 'MINUTES') {
430 script: "ssh -T -i ${SSH_KEY} " +
431 "-o StrictHostKeyChecking=no " +
432 "-o UserKnownHostsFile=/dev/null " +
433 "-o ConnectTimeout=5 ubuntu@${IP_ADDRESS} 'echo Alive'")
434 alive = (output == 0)
437 println('VM is ready and accepting ssh connections')
438 } // stage("Spawn Remote VM")
440 ///////////////////////////////////////////////////////////////////////////////////////
441 // Checks before installation
442 ///////////////////////////////////////////////////////////////////////////////////////
443 stage('Checks before installation') {
448 identityFile: SSH_KEY,
453 // Ensure the VM is ready
454 sshCommand remote: remote, command: 'cloud-init status --wait'
456 // Force time sync to avoid clock drift and invalid certificates
457 sshCommand remote: remote, command: 'sudo apt-get update'
458 sshCommand remote: remote, command: 'sudo apt-get install -y chrony'
459 sshCommand remote: remote, command: 'sudo service chrony stop'
460 sshCommand remote: remote, command: 'sudo chronyd -vq'
461 sshCommand remote: remote, command: 'sudo service chrony start'
463 } // stage("Checks before installation")
464 ///////////////////////////////////////////////////////////////////////////////////////
466 ///////////////////////////////////////////////////////////////////////////////////////
473 if (params.COMMIT_ID) {
474 commit_id = "-b ${params.COMMIT_ID}"
476 if (params.REPO_DISTRO) {
477 repo_distro = "-r ${params.REPO_DISTRO}"
479 if (params.REPO_KEY_NAME) {
480 repo_key_name = "-k ${params.REPO_KEY_NAME}"
482 if (params.RELEASE) {
483 release = "-R ${params.RELEASE}"
485 if (params.REPOSITORY_BASE) {
486 repo_base_url = "-u ${params.REPOSITORY_BASE}"
488 repo_base_url = "-u http://${NODE_IP_ADDRESS}:${repo_port}"
495 identityFile: SSH_KEY,
501 sshCommand remote: remote, command: '''
502 wget https://osm-download.etsi.org/ftp/osm-11.0-eleven/install_osm.sh
503 chmod +x ./install_osm.sh
504 sed -i '1 i\\export PATH=/snap/bin:\$PATH' ~/.bashrc
507 Map gitlabCredentialsMap = [$class: 'UsernamePasswordMultiBinding',
508 credentialsId: 'gitlab-registry',
509 usernameVariable: 'USERNAME',
510 passwordVariable: 'PASSWORD']
511 if (useCharmedInstaller) {
512 // Use local proxy for docker hub
513 sshCommand remote: remote, command: '''
514 sudo snap install microk8s --classic --channel=1.19/stable
515 sudo sed -i "s|https://registry-1.docker.io|http://172.21.1.1:5000|" \
516 /var/snap/microk8s/current/args/containerd-template.toml
517 sudo systemctl restart snap.microk8s.daemon-containerd.service
518 sudo snap alias microk8s.kubectl kubectl
521 withCredentials([gitlabCredentialsMap]) {
522 sshCommand remote: remote, command: """
523 ./install_osm.sh -y \
526 ${release} -r unstable \
528 --registry ${USERNAME}:${PASSWORD}@${INTERNAL_DOCKER_REGISTRY} \
529 --tag ${containerName}
532 prometheusHostname = "prometheus.${IP_ADDRESS}.nip.io"
534 osmHostname = "nbi.${IP_ADDRESS}.nip.io:443"
536 // Run -k8s installer here specifying internal docker registry and docker proxy
537 withCredentials([gitlabCredentialsMap]) {
538 sshCommand remote: remote, command: """
539 ./install_osm.sh -y \
542 ${release} -r unstable \
543 -d ${USERNAME}:${PASSWORD}@${INTERNAL_DOCKER_REGISTRY} \
544 -p ${INTERNAL_DOCKER_PROXY} \
548 prometheusHostname = IP_ADDRESS
549 prometheusPort = 9091
550 osmHostname = IP_ADDRESS
552 } // stage("Install")
553 ///////////////////////////////////////////////////////////////////////////////////////
554 // Health check of installed OSM in remote vm
555 ///////////////////////////////////////////////////////////////////////////////////////
556 stage('OSM Health') {
557 // if this point is reached, logs should be archived
558 ARCHIVE_LOGS_FLAG = true
560 sshCommand remote: remote, command: """
561 /usr/share/osm-devops/installers/osm_health.sh -k -s ${stackName}
563 } // stage("OSM Health")
564 } // if ( params.DO_INSTALL )
567 ///////////////////////////////////////////////////////////////////////////////////////
568 // Execute Robot tests
569 ///////////////////////////////////////////////////////////////////////////////////////
570 stage_archive = false
571 if ( params.DO_ROBOT ) {
573 stage('System Integration Test') {
574 if (useCharmedInstaller) {
575 tempdir = sh(returnStdout: true, script: 'mktemp -d').trim()
576 sh(script: "touch ${tempdir}/hosts")
577 hostfile = "${tempdir}/hosts"
578 sh """cat << EOF > ${hostfile}
580 ${remote.host} prometheus.${remote.host}.nip.io nbi.${remote.host}.nip.io
586 jujuPassword = sshCommand remote: remote, command: '''
587 echo `juju gui 2>&1 | grep password | cut -d: -f2`
592 params.ROBOT_TAG_NAME,
597 params.ROBOT_PORT_MAPPING_VIM,
603 params.ROBOT_PASS_THRESHOLD,
604 params.ROBOT_UNSTABLE_THRESHOLD
606 } // stage("System Integration Test")
608 stage('After System Integration test') {
609 if (currentBuild.result != 'FAILURE') {
610 stage_archive = keep_artifacts
612 println('Systest test failed, throwing error')
613 error = new Exception('Systest test failed')
614 currentBuild.result = 'FAILURE'
619 } // if ( params.DO_ROBOT )
621 if (params.SAVE_ARTIFACTS_OVERRIDE || stage_archive) {
623 // Archive the tested repo
624 dir("${RELEASE_DIR}") {
625 ci_helper.archive(params.ARTIFACTORY_SERVER, RELEASE, GERRIT_BRANCH, 'tested')
627 if (params.DO_DOCKERPUSH) {
628 stage('Publish to Dockerhub') {
630 for (buildStep in containerList) {
631 def module = buildStep
632 def moduleName = buildStep.toLowerCase()
633 def dockerTag = params.DOCKER_TAG
634 def moduleTag = containerName
636 parallelSteps[module] = {
638 sh("docker pull ${INTERNAL_DOCKER_REGISTRY}opensourcemano/${moduleName}:${moduleTag}")
639 sh("""docker tag opensourcemano/${moduleName}:${moduleTag} \
640 opensourcemano/${moduleName}:${dockerTag}""")
641 sh "docker push opensourcemano/${moduleName}:${dockerTag}"
645 parallel parallelSteps
647 stage('Snap promotion') {
648 withCredentials([string(credentialsId: 'Snapstore', variable: 'SNAPCRAFT_STORE_CREDENTIALS')]) {
649 snaps = ['osmclient']
650 for (snap in snaps) {
652 if (BRANCH_NAME.startsWith('v')) {
653 channel = BRANCH_NAME.substring(1) + '/'
654 } else if (BRANCH_NAME != 'master') {
655 channel += '/' + BRANCH_NAME.replaceAll('/', '-')
657 track = channel + 'edge\\*'
658 edge_rev = sh(returnStdout: true,
659 script: "snapcraft revisions $snap | " +
660 "grep \"$track\" | tail -1 | awk '{print \$1}'").trim()
661 track = channel + 'beta\\*'
662 beta_rev = sh(returnStdout: true,
663 script: "snapcraft revisions $snap | " +
664 "grep \"$track\" | tail -1 | awk '{print \$1}'").trim()
666 print "Edge: $edge_rev, Beta: $beta_rev"
668 if (edge_rev != beta_rev) {
669 print "Promoting $edge_rev to beta in place of $beta_rev"
670 beta_track = channel + 'beta'
671 sh "snapcraft release $snap $edge_rev $beta_track"
675 } // stage('Snap promotion')
676 stage('Charm promotion') {
690 for (charm in charms) {
693 if (BRANCH_NAME.startsWith('v')) {
694 channel = BRANCH_NAME.substring(1)
695 } else if (BRANCH_NAME != 'master') {
696 channel += '/' + BRANCH_NAME.replaceAll('/', '-')
699 withCredentials([string(credentialsId: 'Charmstore', variable: 'CHARMCRAFT_AUTH')]) {
700 sh "charmcraft status $charm --format json > ${charm}.json"
701 isCharm = sh(returnStdout: true, script: "grep architecture ${charm}.json | wc -l").trim() as int
703 jqScriptEdge = "cat ${charm}.json | jq -r '.[] | select(.track==\"$channel\") | .mappings[] | select(.base.architecture==\"amd64\" and .base.channel==\"20.04\") | .releases[] | select(.channel==\"$channel/edge/merged\")| .version'|head -1"
704 jqScriptBeta = "cat ${charm}.json | jq -r '.[] | select(.track==\"$channel\") | .mappings[] | select(.base.architecture==\"amd64\" and .base.channel==\"20.04\") | .releases[] | select(.channel==\"$channel/beta\")| .version'|head -1"
706 jqScriptEdge = "cat ${charm}.json | jq -r '.[] | select(.track==\"$channel\") | .mappings[].releases[] | select(.channel==\"$channel/edge/merged\")| .version'|head -1"
707 jqScriptBeta = "cat ${charm}.json | jq -r '.[] | select(.track==\"$channel\") | .mappings[].releases[] | select(.channel==\"$channel/beta\")| .version'|head -1"
709 // edge/merged is used in place of /edge as 10.1.0 LTS uses latest/edge
710 edge_rev = sh(returnStdout: true, script: jqScriptEdge).trim()
711 beta_rev = sh(returnStdout: true, script: jqScriptBeta).trim()
712 try { edge_rev = edge_rev as int } catch (NumberFormatException nfe) {edge_rev = 0}
713 try { beta_rev = beta_rev as int } catch (NumberFormatException nfe) {beta_rev = 0}
715 print "Edge: $edge_rev, Beta: $beta_rev"
717 if (edge_rev > beta_rev) {
718 print "Promoting $edge_rev to beta in place of $beta_rev"
719 beta_track = channel + 'beta'
720 sh "charmcraft release ${charm} --revision=${edge_rev} --channel=${channel}/beta"
725 } // stage('Charm promotion')
726 } // if (params.DO_DOCKERPUSH)
727 } // stage('Archive')
728 } // if (params.SAVE_ARTIFACTS_OVERRIDE || stage_archive)
731 stage('Archive Container Logs') {
732 if (ARCHIVE_LOGS_FLAG) {
739 identityFile: SSH_KEY,
744 println('Archiving container logs')
746 } catch (Exception e) {
747 println('Error fetching logs: '+ e.getMessage())
749 } // end if ( ARCHIVE_LOGS_FLAG )
752 if (params.DO_INSTALL && server_id != null) {
754 if (error && params.SAVE_CONTAINER_ON_FAIL) {
757 if (!error && params.SAVE_CONTAINER_ON_PASS) {
762 if (server_id != null) {
763 println("Deleting VM: $server_id")
765 for line in `grep OS ~/hive/robot-systest.cfg | grep -v OS_CLOUD` ; do export \$line ; done
766 openstack server delete ${server_id}
769 println("Saved VM $server_id in ETSI VIM")
773 if (http_server_name != null) {
774 sh "docker stop ${http_server_name} || true"
775 sh "docker rm ${http_server_name} || true"
778 if (devopstempdir != null) {
779 sh "rm -rf ${devopstempdir}"