jobs/updateSrcRevisions: added functionality to the skeleton
Signed-off-by: Marc Mattmüller <marc.mattmueller@netmodule.com>
This commit is contained in:
parent
c79814899b
commit
2a56bbd0e8
|
|
@ -10,6 +10,7 @@ pipeline {
|
||||||
parameters {
|
parameters {
|
||||||
string(name: 'BUILD_BRANCH', defaultValue: 'main', description: 'Enter the branch of the NWL to build (default = main), will skip deployment if not main')
|
string(name: 'BUILD_BRANCH', defaultValue: 'main', description: 'Enter the branch of the NWL to build (default = main), will skip deployment if not main')
|
||||||
booleanParam(name: 'CLEAN_BUILD', defaultValue: false, description: 'do a clean build, i.e. remove the yocto directory and start from scratch')
|
booleanParam(name: 'CLEAN_BUILD', defaultValue: false, description: 'do a clean build, i.e. remove the yocto directory and start from scratch')
|
||||||
|
booleanParam(name: 'DRY_RUN', defaultValue: true, description: 'do a dry run, i.e. without committing and pushing')
|
||||||
}
|
}
|
||||||
|
|
||||||
options {
|
options {
|
||||||
|
|
@ -24,7 +25,13 @@ pipeline {
|
||||||
stage('Prepare') {
|
stage('Prepare') {
|
||||||
steps {
|
steps {
|
||||||
script {
|
script {
|
||||||
println "ToDo: prepare stage"
|
printJobParameters()
|
||||||
|
setDisplayName()
|
||||||
|
|
||||||
|
// load common file
|
||||||
|
common = load "./jobs/Jenkinsfile_Common"
|
||||||
|
|
||||||
|
handleCleanBuild(common)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -32,10 +39,80 @@ pipeline {
|
||||||
stage('Update') {
|
stage('Update') {
|
||||||
steps {
|
steps {
|
||||||
script {
|
script {
|
||||||
println "ToDo: Update stage"
|
updateTheSourceRevisions(common, "${params.BUILD_BRANCH}")
|
||||||
|
commitAndPushTheChanges(common)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
post {
|
||||||
|
always {
|
||||||
|
script {
|
||||||
|
common.cleanupRepository("./")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // stages
|
} // stages
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
def printJobParameters() {
|
||||||
|
println "----------------------------------\n\
|
||||||
|
Job Parameters:\n\
|
||||||
|
----------------------------------\n\
|
||||||
|
BUILD_BRANCH = ${params.BUILD_BRANCH}\n\
|
||||||
|
CLEAN_BUILD = ${params.CLEAN_BUILD}\n\
|
||||||
|
DRY_RUN = ${params.DRY_RUN}\n\
|
||||||
|
----------------------------------\n"
|
||||||
|
}
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
def setDisplayName() {
|
||||||
|
def buildName = "#${env.BUILD_NUMBER}"
|
||||||
|
def theBranch = "${params.BUILD_BRANCH}"
|
||||||
|
def cleaning = ("${params.CLEAN_BUILD}" == true) ? "-clean" : ""
|
||||||
|
currentBuild.displayName = "${buildName}-${theBranch}${cleaning}"
|
||||||
|
}
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
def handleCleanBuild(commonHelpers) {
|
||||||
|
if(params.CLEAN_BUILD) {
|
||||||
|
println "CLEAN BUILD REQUESTED, cleaning..."
|
||||||
|
commonHelpers.cleaningClonedRepoDir()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
def updateTheSourceRevisions(commonHelpers, theBranch) {
|
||||||
|
commonHelpers.gitUpdateSubmodulesCheckoutBranch(theBranch, true, true)
|
||||||
|
commonHelpers.printSubmoduleStatus(true)
|
||||||
|
}
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
def commitAndPushTheChanges(commonHelpers) {
|
||||||
|
def commitMsg = "srcrev: updated source revisions by Jenkins Job"
|
||||||
|
|
||||||
|
if(sh(returnStdout: true, script: "git status | grep \"modified:\" | grep -v coreos | wc -l").toInteger() != 0) {
|
||||||
|
def itemFindCmd = "git status | grep \"modified:\" | grep -v coreos | cut -d':' -f2 | sed -e 's/^[ ]*//' | cut -d' ' -f1"
|
||||||
|
def changedItems = sh(returnStdout: true, script: "${itemFindCmd}")
|
||||||
|
sh(label: "Stage tracked and changed git files", returnStdout: true, script: "git add ${changedItems}")
|
||||||
|
|
||||||
|
if(params.DRY_RUN) {
|
||||||
|
println "DRY RUN: commit message = '${commitMsg}'\n changes = ${changedItems}"
|
||||||
|
sh(script: """
|
||||||
|
git reset HEAD * > /dev/null
|
||||||
|
git checkout * > /dev/null
|
||||||
|
""")
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
println "ToDo: commit and push the changes"
|
||||||
|
//NOTE: The following code snippet may help...
|
||||||
|
//def theCredentials = getGitCredentialID()
|
||||||
|
//sshagent (credentials: [theCredentials]) {
|
||||||
|
// sh(label: "Commit and push changes", returnStdout: true, script: """
|
||||||
|
// git commit -m "${commitMsg}"
|
||||||
|
// git push
|
||||||
|
// """)
|
||||||
|
//}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue