From ed78e8d10033e500903e78881485d0afac9e5565 Mon Sep 17 00:00:00 2001 From: mesaj Date: Fri, 29 Aug 2025 10:04:51 +0200 Subject: [PATCH] fix(stage_3): docker run output Change-Id: Ibfe28327b5ec3f64528a876b4f16d6cdd3c48127 Signed-off-by: mesaj --- jenkins/ci-pipelines/ci_stage_3.groovy | 37 ++++++++++++++++++-------- 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/jenkins/ci-pipelines/ci_stage_3.groovy b/jenkins/ci-pipelines/ci_stage_3.groovy index eaf60090..b4cb672b 100644 --- a/jenkins/ci-pipelines/ci_stage_3.groovy +++ b/jenkins/ci-pipelines/ci_stage_3.groovy @@ -84,8 +84,9 @@ class DockerRunner implements Serializable { def steps // Jenkins DSL context (`this` from the script) DockerRunner(def steps) { this.steps = steps } - /** Returns stdout (trimmed); throws Exception on non-zero exit. */ + /** Returns stdout (trimmed) if returnStdout is true; throws Exception on non-zero exit */ String run(Map args = [:]) { + def returnStdout = args.remove('returnStdout') ?: false def envFile = args.envFile ?: '' def entry = args.entry ? "--entrypoint ${args.entry}" : '' def mounts = (args.mounts ?: []) @@ -96,15 +97,21 @@ class DockerRunner implements Serializable { .collect { "--env ${it}" }.join(' ') def image = args.image ?: '' def cmd = args.cmd ?: '' - def fullCmd = """docker run ${entry} ${envs} ${envFile ? "--env-file ${envFile}" : ''} ${mounts} ${image} ${cmd}""".trim().replaceAll('\\s+', ' ') + def fullCmd = """docker run ${entry} ${envs} ${envFile ? "--env-file ${envFile}" : ''} ${mounts} ${image} ${cmd}""" + def result = null try { - return steps.sh(returnStdout: true, script: fullCmd).trim() + if (returnStdout) { + result = steps.sh(returnStdout: true, script: fullCmd).trim() + } else { + steps.sh(script: fullCmd) + } } catch (Exception ex) { throw new Exception("docker run failed → ${ex.message}") } finally { steps.echo("Command executed: ${fullCmd}") } + return result } } @@ -152,6 +159,7 @@ void create_vcluster(String tagName, String kubeconfigPath) { while (System.currentTimeMillis() < deadline) { try { lastOut = dr.run( + returnStdout: true, image : image, entry : "/bin/sh", envVars : envs, @@ -236,7 +244,8 @@ void register_etsi_vim_account( "${portmappingfile}:/root/port-mapping.yaml", "${prometheusconfigfile}:/root/etsi-vim-prometheus.json" ], - cmd : entrypointArgs + cmd : entrypointArgs, + returnStdout: true ) println("VIM Creation Output: ${createOutput}") } @@ -257,7 +266,8 @@ void register_etsi_vim_account( "${portmappingfile}:/root/port-mapping.yaml", "${prometheusconfigfile}:/root/etsi-vim-prometheus.json" ], - cmd : entrypointArgs + cmd : entrypointArgs, + returnStdout: true ) println("VIM List output: ${vimList}") if (vimList.contains("ENABLED")) { @@ -270,7 +280,7 @@ void register_etsi_vim_account( // If stuck, delete and retry println("VIM stuck for more than 50 seconds, deleting and retrying...") entrypointArgs = """vim-delete --force ${VIM_TARGET}""" - String vimList = dr.run( + String deleteOutput = dr.run( image : "opensourcemano/tests:${tagName}", entry : entrypointCmd, envVars : [ "OSM_HOSTNAME=${osmHostname}" ], @@ -281,7 +291,8 @@ void register_etsi_vim_account( "${portmappingfile}:/root/port-mapping.yaml", "${prometheusconfigfile}:/root/etsi-vim-prometheus.json" ], - cmd : entrypointArgs + cmd : entrypointArgs, + returnStdout: true ) println("VIM Deletion Output: ${deleteOutput}") sleep(5) @@ -336,7 +347,8 @@ void register_etsi_k8s_cluster( "${portmappingfile}:/root/port-mapping.yaml", "${prometheusconfigfile}:/root/etsi-vim-prometheus.json" ], - cmd : entrypointArgs + cmd : entrypointArgs, + returnStdout: true ) println("K8s Cluster Addition Output: ${createOutput}") @@ -356,7 +368,8 @@ void register_etsi_k8s_cluster( "${portmappingfile}:/root/port-mapping.yaml", "${prometheusconfigfile}:/root/etsi-vim-prometheus.json" ], - cmd : entrypointArgs + cmd : entrypointArgs, + returnStdout: true ) println("K8s Cluster List Output: ${clusterList}") if (clusterList.contains("ENABLED")) { @@ -380,7 +393,8 @@ void register_etsi_k8s_cluster( "${portmappingfile}:/root/port-mapping.yaml", "${prometheusconfigfile}:/root/etsi-vim-prometheus.json" ], - cmd : entrypointArgs + cmd : entrypointArgs, + returnStdout: true ) println("K8s Cluster Show Output: ${showOutput}") entrypointArgs = """k8scluster-delete ${K8S_CLUSTER_TARGET}""" @@ -395,7 +409,8 @@ void register_etsi_k8s_cluster( "${portmappingfile}:/root/port-mapping.yaml", "${prometheusconfigfile}:/root/etsi-vim-prometheus.json" ], - cmd : entrypointArgs + cmd : entrypointArgs, + returnStdout: true ) println("K8s Cluster Deletion Output: ${deleteOutput}") sleep(5) -- 2.25.1