jobs/common: refactored gitCheckout() for using more flexible
the function gitCheckout() holds the following steps: - git clone unless done - checking out a branch/tag/commit including rebase and updating submodules - launching the update source revision script - printing the submodule status - printing the last 3 commits of the git history But so far you could not use the steps separately. Thus, this function was refactored by extracting some steps into own functions so that they can be used easily. Example: the job workspace is the cloned git repository and you want to update the source revision hashes ;-P Signed-off-by: Marc Mattmüller <marc.mattmueller@netmodule.com>
This commit is contained in:
parent
54161e2b5c
commit
be603724d2
|
|
@ -118,8 +118,31 @@ def removePreExistingYoctoConfigs(confPath) {
|
|||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
def gitCheckout(gitUrl, branchTag, repoDir, hasSubmodules) {
|
||||
println "checking out ${gitUrl} to ${repoDir}..."
|
||||
def printLatestGitHistory() {
|
||||
gitHistory = sh(returnStdout: true, script: "git log --pretty=oneline -3")
|
||||
println "Last 3 git commits:\n-----------------------------\n${gitHistory}"
|
||||
}
|
||||
//-----------------------------------------------------------------------------
|
||||
def printSubmoduleStatus(hasSubmodules = true) {
|
||||
if(hasSubmodules) {
|
||||
submoduleStatus = sh(script: "git submodule status", returnStdout: true)
|
||||
println "${submoduleStatus}"
|
||||
}
|
||||
}
|
||||
//-----------------------------------------------------------------------------
|
||||
def gitUpdateSubmodulesCheckoutBranch(branchTag, hasSubmodules, doUpdatePackageSrcRevisions) {
|
||||
def gitCredentials = getGitCredentialID()
|
||||
def updateSubmodulesCmd = hasSubmodules ? " && git submodule update --init --recursive" : ""
|
||||
sshagent (credentials: [gitCredentials]) {
|
||||
sh(script: "git checkout ${branchTag} && git pull --rebase ${updateSubmodulesCmd}")
|
||||
if(doUpdatePackageSrcRevisions) {
|
||||
sh(label: "Temporary task - updating source revisions (sub-repositories)",
|
||||
script: "./scripts/update-source-revisions.sh")
|
||||
}
|
||||
}
|
||||
}
|
||||
//-----------------------------------------------------------------------------
|
||||
def cloneGitRepoUnlessExisting(gitUrl, repoDir, hasSubmodules) {
|
||||
def gitCredentials = getGitCredentialID()
|
||||
if(!fileExists("./${repoDir}")) {
|
||||
sshagent (credentials: [gitCredentials]) {
|
||||
|
|
@ -127,21 +150,16 @@ def gitCheckout(gitUrl, branchTag, repoDir, hasSubmodules) {
|
|||
sh(script: "git clone ${inclSubmodulesOpt} ${gitUrl} ${repoDir}")
|
||||
}
|
||||
}
|
||||
dir("${repoDir}") {
|
||||
def updateSubmodulesCmd = hasSubmodules ? " && git submodule update --init --recursive" : ""
|
||||
sshagent (credentials: [gitCredentials]) {
|
||||
sh(script: "git fetch -ap && git fetch -t")
|
||||
sh(script: "git checkout ${branchTag} && git pull --rebase ${updateSubmodulesCmd}")
|
||||
}
|
||||
//-----------------------------------------------------------------------------
|
||||
def gitCheckout(gitUrl, branchTag, repoDir, hasSubmodules, doUpdatePackageSrcRevisions = true) {
|
||||
println "checking out git repository ${gitUrl} to ${repoDir}..."
|
||||
cloneGitRepoUnlessExisting(gitUrl, repoDir, hasSubmodules)
|
||||
|
||||
sh(label: "Temporary task - updating source revisions (sub-repositories)",
|
||||
script: "./scripts/update-source-revisions.sh")
|
||||
}
|
||||
if(hasSubmodules) {
|
||||
submoduleStatus = sh(script: "git submodule status", returnStdout: true)
|
||||
println "${submoduleStatus}"
|
||||
}
|
||||
gitHistory = sh(returnStdout: true, script: "git log --pretty=oneline -3")
|
||||
println "Last 3 git commits:\n-----------------------------\n${gitHistory}"
|
||||
dir("${repoDir}") {
|
||||
gitUpdateSubmodulesCheckoutBranch(branchTag, hasSubmodules, doUpdatePackageSrcRevisions)
|
||||
printSubmoduleStatus(hasSubmodules)
|
||||
printLatestGitHistory()
|
||||
}
|
||||
}
|
||||
//-----------------------------------------------------------------------------
|
||||
|
|
|
|||
Loading…
Reference in New Issue