mirror of
https://gitlab.eurecom.fr/oai/openairinterface5g.git
synced 2026-07-13 04:30:28 +00:00
CI: adapt Jenkinsfile-push-local-repo for GitHub PR merge refs
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>
This commit is contained in:
@@ -23,11 +23,54 @@ pipeline {
|
||||
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.sourceRepo?.trim()) { missingParams << 'sourceRepo' }
|
||||
if (!params.sourceBranch?.trim()) { missingParams << 'sourceBranch' }
|
||||
if (!params.sourceCommit?.trim()) { missingParams << 'sourceCommit' }
|
||||
if (params.mergeWithTarget) {
|
||||
@@ -39,7 +82,6 @@ pipeline {
|
||||
error "Missing required parameters: ${missingParams.join(', ')}"
|
||||
}
|
||||
|
||||
echo "Source Repo : ${params.sourceRepo}"
|
||||
echo "Source Branch : ${params.sourceBranch}"
|
||||
echo "Source Commit : ${params.sourceCommit}"
|
||||
echo "Merge : ${params.mergeWithTarget}"
|
||||
@@ -53,49 +95,17 @@ pipeline {
|
||||
stage('Prepare workspace') {
|
||||
steps {
|
||||
sh """
|
||||
git config user.email "jenkins@openairinterface.org"
|
||||
git config user.name "OAI Jenkins"
|
||||
git remote remove source || true
|
||||
git remote remove target || true
|
||||
git config user.email "oaicicdteam@openairinterface.org"
|
||||
git config user.name "Duranta Jenkins"
|
||||
git remote remove internal-repo || true
|
||||
"""
|
||||
}
|
||||
}
|
||||
stage('Add source repo & fetch branches') {
|
||||
steps {
|
||||
sh """
|
||||
git remote add source ${params.sourceRepo} || true
|
||||
git fetch source ${params.sourceBranch}
|
||||
"""
|
||||
script {
|
||||
if (params.mergeWithTarget) {
|
||||
sh """
|
||||
git remote add target ${params.targetRepo} || true
|
||||
git fetch target ${params.targetBranch}
|
||||
"""
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
stage('Create testing branch for CI') {
|
||||
steps {
|
||||
sh """
|
||||
# Checkout source commit
|
||||
git checkout -B ${params.branch} ${params.sourceCommit}
|
||||
"""
|
||||
}
|
||||
}
|
||||
stage('Merge target into source') {
|
||||
when { expression { return params.mergeWithTarget } }
|
||||
steps {
|
||||
sh """
|
||||
echo "Merging target branch ${params.targetBranch} into source branch ${params.branch}"
|
||||
if ! git merge --ff target/${params.targetBranch} \
|
||||
-m "Merge ${params.targetBranch} into ${params.sourceBranch} for CI"; then
|
||||
echo "Merge conflicts detected. Aborting."
|
||||
git merge --abort || true
|
||||
exit 1
|
||||
fi
|
||||
git checkout -B ${params.branch}
|
||||
"""
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,9 +46,9 @@ pipeline {
|
||||
stage ("Push to DockerHub") {
|
||||
steps {
|
||||
script {
|
||||
WEEK_REF = sh returnStdout: true, script: 'date +"%Y.w%V"'
|
||||
def WEEK_REF = sh returnStdout: true, script: 'date +"%Y.w%V"'
|
||||
WEEK_REF = WEEK_REF.trim()
|
||||
WEEK_TAG = sh returnStdout: true, script: 'python3 ./ci-scripts/provideUniqueImageTag.py --start_tag ' + WEEK_REF
|
||||
def WEEK_TAG = sh returnStdout: true, script: 'python3 ./ci-scripts/provideUniqueImageTag.py --start_tag ' + WEEK_REF
|
||||
WEEK_TAG = WEEK_TAG.trim()
|
||||
if ((params.forceTag != null) && (params.tagToUse != null)) {
|
||||
if (params.forceTag) {
|
||||
@@ -56,7 +56,7 @@ pipeline {
|
||||
echo "Forced Tag is ${WEEK_TAG}"
|
||||
}
|
||||
}
|
||||
WEEK_SHA = sh returnStdout: true, script: 'git log -n1 --pretty=format:"%H" origin/develop'
|
||||
def WEEK_SHA = sh returnStdout: true, script: 'git log -n1 --pretty=format:"%H" origin/develop'
|
||||
WEEK_SHA = WEEK_SHA.trim()
|
||||
|
||||
withCredentials([
|
||||
|
||||
Reference in New Issue
Block a user