CI: replace CreateTag and merge-based workspace logic with explicit branch/repo

Remove CreateTag() and the merge/targetBranch parameters from
CreateWorkspace, passing the final branch name and repository directly
from Jenkins instead. Jenkinsfile computes testBranch and testRepository
(with INTERNAL_REPO as default). create_workspace.sh now does a simple
shallow clone by branch name.

Introduce two optional Jenkins parameters that allow overriding the
default branch reference and git repository URL used across the CI
pipeline.
- customBranch: when set, replaces the entire computed
  {sourceBranch}-{commitID}
- customRepository: when set, replaces INTERNAL_REPO as the git remote
  used by Create_Workspace to clone the source code onto the test node.

Signed-off-by: Jaroslava Fiedlerova <jaroslava.fiedlerova@openairinterface.org>
This commit is contained in:
Jaroslava Fiedlerova
2026-05-19 11:38:46 +02:00
parent 06fa702c7c
commit 84299bcd27
8 changed files with 32 additions and 67 deletions

View File

@@ -20,11 +20,12 @@ if (params.LockResources != null && params.LockResources.trim().length() > 0)
// Global Parameters. Normally they should be populated when the master job
// triggers the slave job with parameters
def sourceRepository = params.eNB_Repository ?: env.GIT_URL
def INTERNAL_REPO = "asterix:/home/git/openairinterface5g.git"
def sourceBranch = params.eNB_Branch ?: env.GIT_BRANCH
def targetRepository = params.Target_Repository ?: sourceRepository
def targetBranch = params.eNB_TargetBranch ?: 'develop'
def commitID = params.eNB_CommitID ?: env.GIT_COMMIT
def testRepository = params.customRepository ?: INTERNAL_REPO
def testBranch = params.customBranch ?: "${sourceBranch}-${commitID}"
def is_MR = params.eNB_mergeRequest ?: false
def flexricOption = ""
@@ -84,11 +85,8 @@ pipeline {
}
echo "CI executor node : ${pythonExecutor}"
echo "Source Repository : ${sourceRepository}"
echo "Source Branch : ${sourceBranch}"
echo "Target Repository : ${targetRepository}"
echo "Target Branch : ${targetBranch}"
echo "Commit ID : ${commitID}"
echo "Testing Repository : ${testRepository}"
echo "Testing Branch : ${testBranch}"
if (allParametersPresent) {
echo '\u2705 \u001B[94m All parameters are present\u001B[0m'
@@ -114,16 +112,16 @@ pipeline {
}
}
sh """
python3 main.py --mode=InitiateHtml --ranRepository=${targetRepository} \
--ranBranch=${sourceBranch} --ranCommitID=${commitID} \
python3 main.py --mode=InitiateHtml --ranRepository=${testRepository} \
--ranBranch=${testBranch} --ranCommitID=${commitID} \
--ranAllowMerge=${is_MR} --ranTargetBranch=${targetBranch} \
${flexricOption} ${mainPythonAllXmlFiles}
"""
if (runWithOC) {
withCredentials([usernamePassword(credentialsId: "${params.OC_Credentials}", usernameVariable: 'OC_Username', passwordVariable: 'OC_Password')]) {
sh """
python3 main.py --mode=InitiateHtml --ranRepository=${targetRepository} \
--ranBranch=${sourceBranch} --ranCommitID=${commitID} \
python3 main.py --mode=InitiateHtml --ranRepository=${testRepository} \
--ranBranch=${testBranch} --ranCommitID=${commitID} \
--ranAllowMerge=${is_MR} --ranTargetBranch=${targetBranch} \
${flexricOption} ${mainPythonAllXmlFiles}
"""
@@ -132,8 +130,8 @@ pipeline {
try {
timeout (time: 60, unit: 'MINUTES') {
sh """
python3 main.py --mode=TesteNB --ranRepository=${targetRepository} \
--ranBranch=${sourceBranch} --ranCommitID=${commitID} \
python3 main.py --mode=TesteNB --ranRepository=${testRepository} \
--ranBranch=${testBranch} \
--ranAllowMerge=${is_MR} --ranTargetBranch=${targetBranch} \
--eNBSourceCodePath=${params.eNB_SourceCodePath} --XMLTestFile=${xmlFile} \
--OCUserName=${OC_Username} --OCPassword=${OC_Password} --OCProjectName=${OC_ProjectName} \
@@ -153,8 +151,8 @@ pipeline {
try {
timeout (time: 60, unit: 'MINUTES') {
sh """
python3 main.py --mode=TesteNB --ranRepository=${targetRepository} \
--ranBranch=${sourceBranch} --ranCommitID=${commitID} \
python3 main.py --mode=TesteNB --ranRepository=${testRepository} \
--ranBranch=${testBranch} \
--ranAllowMerge=${is_MR} --ranTargetBranch=${targetBranch} \
--eNBSourceCodePath=${params.eNB_SourceCodePath} --XMLTestFile=${xmlFile} \
${flexricOption}

View File

@@ -68,10 +68,7 @@ def ArgsParse(argvs,CiTestObj,RAN,HTML,CONTAINERS,HELP,CLUSTER):
CLUSTER.branch=matchReg.group(1)
elif re.match(r'^\-\-ranCommitID=(.*)$', myArgv, re.IGNORECASE):
matchReg = re.match(r'^\-\-ranCommitID=(.*)$', myArgv, re.IGNORECASE)
RAN.commitID=matchReg.group(1)
HTML.commitID=matchReg.group(1)
CONTAINERS.commitID=matchReg.group(1)
CLUSTER.commitID=matchReg.group(1)
elif re.match(r'^\-\-ranTargetBranch=(.*)$', myArgv, re.IGNORECASE):
matchReg = re.match(r'^\-\-ranTargetBranch=(.*)$', myArgv, re.IGNORECASE)
RAN.targetBranch=matchReg.group(1)

View File

@@ -58,7 +58,6 @@ class Cluster:
self.OCRegistry = OCRegistry
self.repository = ""
self.branch = ""
self.commitID = ""
self.merge = False
self.targetBranch = ""
self.cmd = None
@@ -157,7 +156,7 @@ class Cluster:
OC_logout(cmd)
HTML.CreateHtmlTestRow('N/A', 'KO', CONST.OC_LOGIN_FAIL)
return False
tag = cls_containerize.CreateTag(self.commitID, self.branch, self.merge)
tag = self.branch
registry = f'{self.OCRegistry}/{CI_OC_RAN_NAMESPACE}'
success, msg = cls_containerize.Containerize.Pull_Image(cmd, images, tag, tag_prefix, registry, None, None)
OC_logout(cmd)
@@ -174,9 +173,9 @@ class Cluster:
return (image, archiveArtifact(self.cmd, ctx, fn))
def BuildClusterImage(self, ctx, node, HTML):
if self.repository == '' or self.branch == '' or self.commitID == '':
if self.repository == '' or self.branch == '':
HELP.GenericHelp(CONST.Version)
raise ValueError(f'Insufficient Parameter: repository {self.repository} branch {self.branch} commitID {self.commitID}')
raise ValueError(f'Insufficient Parameter: repository {self.repository} branch {self.branch}')
lSourcePath = self.workspace
if node == '' or lSourcePath == '':
raise ValueError('Insufficient Parameter: workspace missing')
@@ -202,7 +201,7 @@ class Cluster:
forceBaseImageBuild = False
if self.merge: # merging MR branch into develop -> temporary image
branchName = self.branch.replace('/','-')
imageTag = f'{branchName}-{self.commitID}'
imageTag = f'{branchName}'
if self.targetBranch == 'develop':
ret = self.cmd.run(f'git diff HEAD..origin/develop -- cmake_targets/build_oai cmake_targets/tools/build_helper docker/Dockerfile.base.rhel9 | grep --colour=never -i INDEX')
result = re.search('index', ret.stdout)
@@ -215,7 +214,7 @@ class Cluster:
forceBaseImageBuild = True
baseTag = 'ci-temp'
else:
imageTag = f'develop-{self.commitID}'
imageTag = self.branch
forceBaseImageBuild = True
# logging to OC Cluster and then switch to corresponding project

View File

@@ -32,34 +32,15 @@ from cls_ci_helper import archiveArtifact
IMAGES = ['oai-enb', 'oai-lte-ru', 'oai-lte-ue', 'oai-gnb', 'oai-nr-cuup', 'oai-gnb-aw2s', 'oai-nr-ue', 'oai-enb-asan', 'oai-gnb-asan', 'oai-lte-ue-asan', 'oai-nr-ue-asan', 'oai-nr-cuup-asan', 'oai-gnb-aerial', 'oai-gnb-fhi72']
DEFAULT_REGISTRY = "gracehopper3-oai.sboai.cs.eurecom.fr"
def CreateWorkspace(host, sourcePath, repository, commitID, targetBranch, merge):
if commitID == '':
logging.error('need commitID in CreateWorkspace()')
raise ValueError('Insufficient Parameter in CreateWorkspace(): need commitID')
def CreateWorkspace(host, sourcePath, repository, branch):
script = "scripts/create_workspace.sh"
options = f"{sourcePath} {repository} {commitID}"
if merge:
if targetBranch == '':
targetBranch = 'develop'
options += f" {targetBranch}"
options = f"{sourcePath} {repository} {branch}"
logging.info(f'execute "{script}" with options "{options}" on node {host}')
with cls_cmd.getConnection(host) as c:
ret = c.exec_script(script, 90, options)
logging.debug(f'"{script}" finished with code {ret.returncode}, output:\n{ret.stdout}')
return ret.returncode == 0
def CreateTag(commitID, branch, merge):
if commitID == 'develop':
return 'develop'
if merge:
# Allowing contributor to have a name/branchName format
branchName = branch.replace('/','-')
tagToUse = f'{branchName}-{commitID}'
else:
tagToUse = f'develop-{commitID}'
return tagToUse
def AnalyzeBuildLogs(image, lf):
committed = False
tagged = False
@@ -174,7 +155,6 @@ class Containerize():
self.repository = ''
self.branch = ''
self.merge = False
self.commitID = ''
self.targetBranch = ''
self.workspace = ''
self.imageKind = ''
@@ -443,7 +423,7 @@ class Containerize():
if self.merge:
orgTag = 'ci-temp'
for image in IMAGES:
tagToUse = tag_prefix + CreateTag(self.commitID, self.branch, self.merge)
tagToUse = tag_prefix + self.branch
imageTag = f"{image}:{tagToUse}"
ret = ssh.run(f'docker image tag {image}:{orgTag} {imagePrefix}/{imageTag}')
if ret.returncode != 0:
@@ -504,7 +484,7 @@ class Containerize():
def Pull_Image_from_Registry(self, HTML, node, images, tag=None, tag_prefix="", registry=DEFAULT_REGISTRY, username="oaicicd", password="oaicicd"):
logging.debug(f'\u001B[1m Pulling image(s) on server: {node}\u001B[0m')
if not tag:
tag = CreateTag(self.commitID, self.branch, self.merge)
tag = self.branch
with cls_cmd.getConnection(node) as cmd:
success, msg = Containerize.Pull_Image(cmd, images, tag, tag_prefix, registry, username, password)
param = f"on node {node}"
@@ -517,7 +497,7 @@ class Containerize():
def Clean_Test_Server_Images(self, HTML, node, images, tag=None):
logging.debug(f'\u001B[1m Cleaning image(s) from server: {node}\u001B[0m')
if not tag:
tag = CreateTag(self.commitID, self.branch, self.merge)
tag = self.branch
status = True
with cls_cmd.getConnection(node) as myCmd:
@@ -536,10 +516,10 @@ class Containerize():
return status
def Create_Workspace(self, node, HTML):
lSourcePath = self.workspace
success = CreateWorkspace(node, lSourcePath, self.repository, self.commitID, self.targetBranch, self.merge)
sourcePath = self.workspace
success = CreateWorkspace(node, sourcePath, self.repository, self.branch)
if success:
HTML.CreateHtmlTestRowQueue('N/A', 'OK', [f"created workspace {lSourcePath}"])
HTML.CreateHtmlTestRowQueue('N/A', 'OK', [f"created workspace {sourcePath} on node {node}"])
else:
HTML.CreateHtmlTestRowQueue('N/A', 'KO', ["cannot create workspace"])
return success

View File

@@ -148,7 +148,7 @@ def ExecuteActionWithParam(action, ctx, node):
elif action == 'Deploy_Run_OC_PhySim':
oc_release = test.findtext('oc_release')
script = "scripts/oc-deploy-physims.sh"
image_tag = cls_containerize.CreateTag(CLUSTER.commitID, CLUSTER.branch, CLUSTER.merge)
image_tag = CLUSTER.branch
options = f"oaicicd-core-for-ci-ran {oc_release} {image_tag} {CLUSTER.workspace}"
workdir = CLUSTER.workspace
success = cls_oaicitest.Deploy_Physim(ctx, HTML, node, workdir, script, options)
@@ -169,7 +169,7 @@ def ExecuteActionWithParam(action, ctx, node):
CONTAINERS.yamlPath = test.findtext('yaml_path')
CONTAINERS.services = test.findtext('services')
CONTAINERS.num_attempts = int(test.findtext('num_attempts') or 1)
CONTAINERS.deploymentTag = cls_containerize.CreateTag(CONTAINERS.commitID, CONTAINERS.branch, CONTAINERS.merge)
CONTAINERS.deploymentTag = CONTAINERS.branch
if action == 'Deploy_Object':
success = CONTAINERS.DeployObject(ctx, node, HTML)
elif action == 'Stop_Object':
@@ -368,7 +368,7 @@ elif re.match('^TesteNB$', mode, re.IGNORECASE) or re.match('^TestUE$', mode, re
if RAN.repository == '' or RAN.branch == '' or RAN.workspace == '':
HELP.GenericHelp(CONST.Version)
if RAN.repository == '':
HELP.GitSrvHelp(RAN.repository, RAN.branch, RAN.commitID, RAN.merge, RAN.targetBranch)
HELP.GitSrvHelp(RAN.repository, RAN.branch, RAN.merge, RAN.targetBranch)
if RAN.workspace == '':
HELP.eNBSrvHelp(RAN.workspace)
sys.exit('Insufficient Parameter')

View File

@@ -35,7 +35,6 @@ class RANManagement():
self.repository = ''
self.branch = ''
self.merge = False
self.commitID = ''
self.targetBranch = ''
self.workspace = ''
self.Initialize_eNB_args = ''

View File

@@ -6,22 +6,16 @@ function die() {
exit 1
}
[ $# -ge 3 -a $# -le 4 ] || die "usage: $0 <directory> <repository> <ref> [<merge-ref>]"
[ $# -eq 3 ] || die "usage: $0 <directory> <repository> <branch>"
set -ex
dir=$1
repo=$2
ref=$3
merge=$4
branch=$3
rm -rf ${dir}
git clone --filter=blob:none -n ${repo} ${dir}
git clone --depth=1 --branch "${branch}" "${repo}" "${dir}"
cd ${dir}
git config user.email "jenkins@openairinterface.org"
git config user.name "OAI Jenkins"
git config advice.detachedHead false
mkdir -p cmake_targets/log
git checkout -f ${ref}
[ -n "${merge}" ] && git fetch origin ${merge} && git merge --ff FETCH_HEAD -m "Temporary merge for CI"
exit 0

View File

@@ -43,7 +43,6 @@ class TestDeploymentMethods(unittest.TestCase):
self.cont.yamlPath = ''
self.cont.merge = True
self.cont.branch = ''
self.cont.commitID = ''
self.cont.workspace = os.getcwd()
self.cont.num_attempts = 3
self.node = 'localhost'
@@ -138,7 +137,6 @@ class TestDeploymentMethods(unittest.TestCase):
def test_create_workspace(self):
self.cont.workspace = tempfile.mkdtemp()
self.cont.repository = "https://gitlab.eurecom.fr/oai/openairinterface5g.git"
self.cont.commitID = "05f9c975eeecbca1bdff5940affad44465f1301f"
self.cont.branch = "develop"
ws = self.cont.Create_Workspace(self.node, self.html)
with cls_cmd.LocalCmd() as cmd: