Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BXMSPROD-2121] add sync-branches job #1537

Merged
merged 1 commit into from
Sep 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions job-dsls/jobs/prod/prod_sync_branches.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* Sync branches of a repository from different GH organizations
*/
def scriptTemplate = this.getClass().getResource("job-scripts/prod_sync_branches.jenkinsfile").text
def parsedScript = scriptTemplate.replaceAll(/<%=\s*(\w+)\s*%>/) { config[it[1]] ?: '' }

def folderPath = "PROD"
folder(folderPath)


pipelineJob("${folderPath}/sync-branches") {
description('This job sync branches of a repository from different GitHub organizations.')

parameters {
stringParam('REPOSITORIES', '', 'List of repositories separated by comma, i.e. kogito-runtimes,kogito-apps')
stringParam('BRANCH', '', 'The branch that is going to be synced, i.e. 8.45.x')
stringParam('SOURCE_ORGANIZATION', 'apache', 'The GitHub organization where the original branch is')
stringParam('TARGET_ORGANIZATION', 'kiegroup', 'The GitHub organization where the branch will be pushed')
}

logRotator {
numToKeep(20)
}

definition {
cps {
script(parsedScript)
sandbox()
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
@Library('jenkins-pipeline-shared-libraries')_

pipeline {
agent {
label 'kie-rhel8 && !built-in'
}

stages {
stage('Clean workspace') {
steps {
cleanWs()
}
}

stage('Print variables') {
steps {
println "[INFO] REPOSITORIES: ${REPOSITORIES}"
println "[INFO] BRANCH: ${BRANCH}"
println "[INFO] SOURCE_ORGANIZATION: ${SOURCE_ORGANIZATION}"
println "[INFO] TARGET_ORGANIZATION: ${TARGET_ORGANIZATION}"
}
}

stage('Sync branch') {
steps {
script {
def repositoriesList = REPOSITORIES.split(',').collect{it as String}
for (repository in repositoriesList) {
cloneSourceRepository(repository)
addTargetAsRemote(repository)
pushBranch(repository)
}
}
}
}
}

post {
always {
cleanWs()
}
}
}

def cloneSourceRepository(String repositoryName) {
def repository = !SOURCE_ORGANIZATION.equals("apache") ? repositoryName : "incubator-kie-${repositoryName}" // remove when incubator is removed from the repos name
def repositoryUrl = "https://github.com/${SOURCE_ORGANIZATION}/${repository}.git"
sh "git clone --branch ${BRANCH} ${repositoryUrl} ${repositoryName}"
}

def addTargetAsRemote(String repositoryName) {
dir (repositoryName) {
def remoteUrl = "https://github.com/${TARGET_ORGANIZATION}/${repositoryName}.git"
githubscm.addRemote(TARGET_ORGANIZATION, remoteUrl)
}
}

def pushBranch(String repositoryName) {
dir (repositoryName) {
githubscm.pushObject(TARGET_ORGANIZATION, BRANCH, "kie-ci3")
}
}