jenkins: provided ssh credentials from master for git commands

Signed-off-by: Marc Mattmueller <marc.mattmueller@netmodule.com>
This commit is contained in:
Marc Mattmueller 2021-10-26 19:24:43 +02:00
parent 6a56c05981
commit 55ac1c7307
2 changed files with 31 additions and 20 deletions

View File

@ -40,6 +40,7 @@ def isRelease(versionParam) {
def handleSubmodules(versionParam) { def handleSubmodules(versionParam) {
sshagent (credentials: ['7767e711-08a4-4c71-b080-197253dd7392']) {
println "init submodules..." println "init submodules..."
sh 'git submodule update --init' sh 'git submodule update --init'
if(isRelease(versionParam)) { if(isRelease(versionParam)) {
@ -50,6 +51,7 @@ def handleSubmodules(versionParam) {
println "setting netmodule submodule hashes to head..." println "setting netmodule submodule hashes to head..."
sh 'git submodule update --remote --rebase meta-netmodule-*' // update our own submodules to HEAD sh 'git submodule update --remote --rebase meta-netmodule-*' // update our own submodules to HEAD
} }
}
submoduleStatus = sh(returnStdout: true, script: "git submodule status").trim() // print submodule hashes to jenkins log submoduleStatus = sh(returnStdout: true, script: "git submodule status").trim() // print submodule hashes to jenkins log
println "${submoduleStatus}" println "${submoduleStatus}"
writeFile(file: "${env.SUBMODULE_VERION_FILE}", text: "${submoduleStatus}") writeFile(file: "${env.SUBMODULE_VERION_FILE}", text: "${submoduleStatus}")
@ -111,8 +113,10 @@ def buildVersionString(imageType, actualBaseVersionString, versionParameter) {
} }
def getVersionString(versionParam, imageType) { def getVersionString(versionParam, imageType) {
sshagent (credentials: ['7767e711-08a4-4c71-b080-197253dd7392']) {
sh 'git fetch -ap' sh 'git fetch -ap'
sh 'git fetch -t' sh 'git fetch -t'
}
def gitCmd = "git describe --tags" def gitCmd = "git describe --tags"
if(!isRelease(versionParam)) { if(!isRelease(versionParam)) {

View File

@ -75,8 +75,9 @@ def printJobParameters() {
} }
def prepareUpdate() { def prepareUpdate() {
sshagent (credentials: ['7767e711-08a4-4c71-b080-197253dd7392']) {
sh 'git submodule update --init' // init submodules used if first checkout sh 'git submodule update --init' // init submodules used if first checkout
}
def userId = "${currentBuild.getBuildCauses()[0].userId}" def userId = "${currentBuild.getBuildCauses()[0].userId}"
def userName = "${currentBuild.getBuildCauses()[0].userName}" def userName = "${currentBuild.getBuildCauses()[0].userName}"
if("${userId}" == "null") { if("${userId}" == "null") {
@ -93,12 +94,14 @@ def prepareUpdate() {
} }
def updateSubmodules(isNmUpdate, isCommunityUpdate) { def updateSubmodules(isNmUpdate, isCommunityUpdate) {
sshagent (credentials: ['7767e711-08a4-4c71-b080-197253dd7392']) {
if(isNmUpdate) { if(isNmUpdate) {
sh(script: "git submodule update --remote --rebase meta-netmodule-*") sh(script: "git submodule update --remote --rebase meta-netmodule-*")
} }
if(isCommunityUpdate) { if(isCommunityUpdate) {
sh(script: "git submodule update --remote --rebase \$(git submodule status | grep -v \"meta-netmodule-*\" | sed 's/^ *//g' | cut -d' ' -f2)") sh(script: "git submodule update --remote --rebase \$(git submodule status | grep -v \"meta-netmodule-*\" | sed 's/^ *//g' | cut -d' ' -f2)")
} }
}
submoduleStatus = sh(returnStdout: true, script: "git submodule status").trim() // print submodule hashes to jenkins log submoduleStatus = sh(returnStdout: true, script: "git submodule status").trim() // print submodule hashes to jenkins log
println "${submoduleStatus}" println "${submoduleStatus}"
writeFile(file: "${env.SUBMODULE_VERSION_FILE}", text: "${submoduleStatus}") writeFile(file: "${env.SUBMODULE_VERSION_FILE}", text: "${submoduleStatus}")
@ -128,7 +131,9 @@ def updateSourceRevisions(isNmUpdate) {
def commitSourceRevisionChanges() { def commitSourceRevisionChanges() {
println "commit source revision changes..." println "commit source revision changes..."
sshagent (credentials: ['7767e711-08a4-4c71-b080-197253dd7392']) {
sh(returnStdout: true, script: "./src-rev-commit.sh -b develop -v -l ./srcrev-commit.log") sh(returnStdout: true, script: "./src-rev-commit.sh -b develop -v -l ./srcrev-commit.log")
}
sh "cat ./srcrev-commit.log >> ./${env.SOURCE_REVISION_UPDATE_LOG}" sh "cat ./srcrev-commit.log >> ./${env.SOURCE_REVISION_UPDATE_LOG}"
} }
@ -147,5 +152,7 @@ def commitChanges(isNmUpdate, isCommunityUpdate) {
println "everything up to date, nothing to commit" println "everything up to date, nothing to commit"
return return
} }
sshagent (credentials: ['7767e711-08a4-4c71-b080-197253dd7392']) {
sh(script: "git commit -m \"submodules: updated ${updatedLayers} hashes, triggered by ${env.TRIGGERED_USER}\" && git push") sh(script: "git commit -m \"submodules: updated ${updatedLayers} hashes, triggered by ${env.TRIGGERED_USER}\" && git push")
} }
}