mirror of
https://gitlab.eurecom.fr/oai/openairinterface5g.git
synced 2026-07-13 04:30:28 +00:00
Replace the manual fetch-and-merge approach with pre-built PR merge refs to simplify checkout and eliminate explicit remote management: - Add Job init stage to set build name and description for traceability - Add Checkout stage that fetches refs/pull/<N>/merge for PR builds and checks out targetBranch directly for push builds - Remove sourceRepo parameter and "Add source repo & fetch branches" stage - Remove "Merge target into source" stage (merge is handled by the GitHub PR merge ref at checkout time) Co-authored-by: Shubhika Garg <shubhika.garg@openairinterface.org> Signed-off-by: Jaroslava Fiedlerova <jaroslava.fiedlerova@openairinterface.org>
123 lines
3.9 KiB
Groovy
123 lines
3.9 KiB
Groovy
#!/bin/groovy
|
|
/*
|
|
* SPDX-License-Identifier: LicenseRef-CSSL-1.0
|
|
*/
|
|
|
|
// Location of the python executor node shall be in the same subnet as the others servers
|
|
def nodeExecutor = params.nodeExecutor
|
|
|
|
// SSH URL of the internal git repository
|
|
def internalRepoURL = params.internalRepoURL
|
|
|
|
// Name of the resource
|
|
def lockResources = []
|
|
if (params.LockResources != null && params.LockResources.trim().length() > 0)
|
|
params.LockResources.trim().split(",").each{lockResources += [resource: it.trim()]}
|
|
|
|
pipeline {
|
|
agent {
|
|
label nodeExecutor
|
|
}
|
|
options {
|
|
ansiColor('xterm')
|
|
lock(extra: lockResources)
|
|
}
|
|
stages {
|
|
stage("Job init") {
|
|
steps {
|
|
buildName "${params.requestNumber ?: params.targetBranch}"
|
|
buildDescription "Branch: ${params.sourceBranch}"
|
|
}
|
|
}
|
|
stage('Checkout') {
|
|
steps {
|
|
script {
|
|
if (params.mergeWithTarget) {
|
|
echo "PR triggered - checking out merge ref for PR #${params.requestNumber}"
|
|
try {
|
|
checkout([
|
|
$class: 'GitSCM',
|
|
branches: [[name: "refs/remotes/origin/pr/${params.requestNumber}/merge"]],
|
|
userRemoteConfigs: [[
|
|
url: params.targetRepo,
|
|
refspec: "+refs/pull/${params.requestNumber}/merge:refs/remotes/origin/pr/${params.requestNumber}/merge",
|
|
credentialsId: 'github-jenkins-duranta'
|
|
]]
|
|
])
|
|
} catch (e) {
|
|
error("Checkout failed for PR #${params.requestNumber} - " +
|
|
"merge ref not found. The PR likely has a conflict with ${params.targetBranch} " +
|
|
"that must be resolved before CI can run. (${e.message})")
|
|
}
|
|
} else {
|
|
echo "Push triggered - checking out branch ${params.targetBranch}"
|
|
try {
|
|
checkout([
|
|
$class: 'GitSCM',
|
|
branches: [[name: params.targetBranch]],
|
|
userRemoteConfigs: [[
|
|
url: params.targetRepo,
|
|
credentialsId: 'github-jenkins-duranta'
|
|
]]
|
|
])
|
|
} catch (e) {
|
|
error("Checkout failed for branch ${params.targetBranch} from ${params.targetRepo}. (${e.message})")
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
stage('Verify parameters') {
|
|
steps {
|
|
script {
|
|
def missingParams = []
|
|
if (!params.sourceBranch?.trim()) { missingParams << 'sourceBranch' }
|
|
if (!params.sourceCommit?.trim()) { missingParams << 'sourceCommit' }
|
|
if (params.mergeWithTarget) {
|
|
if (!params.targetRepo?.trim()) { missingParams << 'targetRepo' }
|
|
if (!params.targetBranch?.trim()) { missingParams << 'targetBranch' }
|
|
}
|
|
|
|
if (missingParams) {
|
|
error "Missing required parameters: ${missingParams.join(', ')}"
|
|
}
|
|
|
|
echo "Source Branch : ${params.sourceBranch}"
|
|
echo "Source Commit : ${params.sourceCommit}"
|
|
echo "Merge : ${params.mergeWithTarget}"
|
|
if (params.mergeWithTarget) {
|
|
echo "Target Branch : ${params.targetBranch}"
|
|
echo "Target Repo : ${params.targetRepo}"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
stage('Prepare workspace') {
|
|
steps {
|
|
sh """
|
|
git config user.email "oaicicdteam@openairinterface.org"
|
|
git config user.name "Duranta Jenkins"
|
|
git remote remove internal-repo || true
|
|
"""
|
|
}
|
|
}
|
|
stage('Create testing branch for CI') {
|
|
steps {
|
|
sh """
|
|
# Checkout source commit
|
|
git checkout -B ${params.branch}
|
|
"""
|
|
}
|
|
}
|
|
stage('Push merged branch to internal repository') {
|
|
steps {
|
|
sh """
|
|
git remote add internal-repo ${params.repository} || true
|
|
echo "Pushing ${params.branch} to internal repo"
|
|
git push --force internal-repo ${params.branch}
|
|
"""
|
|
}
|
|
}
|
|
}
|
|
}
|