jenkinsfile_update2head: added pipeline for automatic submodule updating
BugzID: 73574 Signed-off-by: Marc Mattmueller <marc.mattmueller@netmodule.com>
This commit is contained in:
parent
d04eba6caa
commit
e9ee8240e3
|
|
@ -0,0 +1,113 @@
|
||||||
|
// declarative pipeline
|
||||||
|
pipeline {
|
||||||
|
agent {
|
||||||
|
node {
|
||||||
|
label 'lxbuild4'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
parameters {
|
||||||
|
booleanParam(name: 'UPDATE_NM_PARTS', defaultValue: true, description: 'update the netmodule submodules')
|
||||||
|
booleanParam(name: 'UPDATE_COMMUNITY_PARTS', defaultValue: false, description: 'update the the community submodules')
|
||||||
|
}
|
||||||
|
|
||||||
|
environment {
|
||||||
|
SUBMODULE_VERION_FILE = "submodule_revisions"
|
||||||
|
}
|
||||||
|
|
||||||
|
options {
|
||||||
|
timeout(time: 8, unit: 'HOURS')
|
||||||
|
buildDiscarder(
|
||||||
|
logRotator(numToKeepStr: '5',
|
||||||
|
daysToKeepStr: '5',
|
||||||
|
artifactNumToKeepStr: '5',
|
||||||
|
artifactDaysToKeepStr: '5'
|
||||||
|
)
|
||||||
|
)
|
||||||
|
disableConcurrentBuilds()
|
||||||
|
}
|
||||||
|
|
||||||
|
stages {
|
||||||
|
stage('prepare') {
|
||||||
|
steps {
|
||||||
|
script {
|
||||||
|
printJobParameters()
|
||||||
|
prepareUpdate()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
stage('update to head') {
|
||||||
|
steps {
|
||||||
|
script {
|
||||||
|
updateSubmodules(params.UPDATE_NM_PARTS, params.UPDATE_COMMUNITY_PARTS)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
stage('commit') {
|
||||||
|
steps {
|
||||||
|
commitChanges()
|
||||||
|
}
|
||||||
|
post {
|
||||||
|
success {
|
||||||
|
archiveArtifacts(artifacts: "${env.SUBMODULE_VERION_FILE}", onlyIfSuccessful: false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} // stages
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def printJobParameters() {
|
||||||
|
println "----------------------------------\n\
|
||||||
|
Job Parameters:\n\
|
||||||
|
----------------------------------\n\
|
||||||
|
UPDATE_NM_PARTS = ${params.UPDATE_NM_PARTS}\n\
|
||||||
|
UPDATE_COMMUNITY_PARTS = ${params.UPDATE_COMMUNITY_PARTS}\n\
|
||||||
|
----------------------------------\n"
|
||||||
|
}
|
||||||
|
|
||||||
|
def prepareUpdate() {
|
||||||
|
sh 'git submodule init' // init submodules used if first checkout
|
||||||
|
|
||||||
|
def userId = currentBuild.rawBuild.getCause(Cause.UserIdCause).getUserId()
|
||||||
|
println "userId = ${userId}"
|
||||||
|
|
||||||
|
def userIdCause = currentBuild.getBuildCauses('hudson.model.Cause$UserIdCause')[0]
|
||||||
|
println userIdCause
|
||||||
|
|
||||||
|
def buildCause = currentBuild.getBuildCauses('hudson.model.Cause$UserIdCause')
|
||||||
|
println "userName: ${buildCause.userName}"
|
||||||
|
|
||||||
|
def triggerDescription = "${currentBuild.getBuildCauses()[0].shortDescription}"
|
||||||
|
def triggerUserId = "${currentBuild.getBuildCauses()[0].userId}"
|
||||||
|
println "description: ${triggerDescription} ; userId: ${triggerUserId}"
|
||||||
|
|
||||||
|
def notNmUpdate = "${!params.BUILD_FROM_DEV_IMAGE}"
|
||||||
|
def notCommunityUpdate = "${!params.BUILD_FROM_DEV_IMAGE}"
|
||||||
|
if(notNmUpdate.toBoolean() && notCommunityUpdate.toBoolean()) {
|
||||||
|
error("Nothing to update selected - both parameters are false")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
def updateSubmodules(isNmUpdate, isCommunityUpdate) {
|
||||||
|
def updatedPart = ""
|
||||||
|
if(isNmUpdate) {
|
||||||
|
sh(script: "git submodule update --remote --rebase meta-netmodule-*"
|
||||||
|
updatedPart = "netmodule"
|
||||||
|
}
|
||||||
|
if(isCommunityUpdate) {
|
||||||
|
sh(script: "git submodule update --remote --rebase \$(git submodule status | grep -v \"meta-netmodule-*\" | sed 's/^ *//g' | cut -d' ' -f2)")
|
||||||
|
updatedPart = "community"
|
||||||
|
}
|
||||||
|
submoduleStatus = sh(returnStdout: true, script: "git submodule status").trim() // print submodule hashes to jenkins log
|
||||||
|
println "${submoduleStatus}"
|
||||||
|
writeFile(file: "${env.SUBMODULE_VERION_FILE}", text: "${submoduleStatus}")
|
||||||
|
}
|
||||||
|
|
||||||
|
def commitChanges() {
|
||||||
|
sh(script: "git add -u")
|
||||||
|
sh(script: "git commit -m \"submodules: updated ${updatedPart} hashes\" && git push")
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue