jobs: adding git credentials and finalized pre-node step

need to clone the repository to load the list of the buid
targets in pre-node step.

added a git credential ID getter to clone repositories.

Signed-off-by: Marc Mattmüller <marc.mattmueller@netmodule.com>
This commit is contained in:
Marc Mattmüller 2023-04-18 08:47:12 +02:00
parent 4251812565
commit eb19873605
2 changed files with 21 additions and 7 deletions

View File

@ -11,11 +11,18 @@ def targetList
// of a certain label (like core-os_buildagent) to have define credentials to get
// the files. In the current case we use any agent.
node() {
// get the list of the targets:
targetList = sh(returnStdout: true, script: "cat ./jobs/nwlTargets").trim()
dir("tmp-repo") {
// clone the repository to get the file with the target list
sshagent (credentials: ['admin_credentials']) {
sh "git clone --depth 1 --branch ${env.BRANCH_NAME} ssh://git@bitbucket.gad.local:7999/nm-nsp/nwl-ci.git ."
}
// load common file
common = load "./jobs/Jenkinsfile_Common"
// get the list of the targets:
targetList = sh(returnStdout: true, script: "cat ./jobs/nwlTargets").trim()
// load common file
common = load "./jobs/Jenkinsfile_Common"
}
}
// declarative pipeline

View File

@ -40,6 +40,11 @@ def cleaningClonedRepoDir() {
sh("git clean -ffdx")
}
//-----------------------------------------------------------------------------
def getGitCredentialID() {
return 'admin_credentials'
}
//-----------------------------------------------------------------------------
def setupGlobalEnvironmentVariables(repoDir, machine) {
@ -73,15 +78,16 @@ def removePreExistingYoctoConfigs(confPath) {
//-----------------------------------------------------------------------------
def gitCheckout(gitUrl, branchTag, repoDir, hasSubmodules) {
println "checking out ${gitUrl} to ${repoDir}..."
def gitCredentials = getGitCredentialID()
if(!fileExists("./${repoDir}")) {
sshagent (credentials: [env.SSH_ID]) {
sshagent (credentials: [gitCredentials]) {
def inclSubmodulesOpt = hasSubmodules ? "--recurse-submodules" : ""
sh(script: "git clone ${inclSubmodulesOpt} ${gitUrl} ${repoDir}")
}
}
dir("${repoDir}") {
def updateSubmodulesCmd = hasSubmodules ? " && git submodule update --init --recursive" : ""
sshagent (credentials: [env.SSH_ID]) {
sshagent (credentials: [gitCredentials]) {
sh(script: "git fetch -ap && git fetch -t")
sh(script: "git checkout ${branchTag} && git pull --rebase ${updateSubmodulesCmd}")
}
@ -232,7 +238,8 @@ def buildTheYoctoPackage() {
def buildCall = "bitbake ${env.BITBAKE_CMD} >> ${env.SHARED_BUILD}/${yoctoOutFile} 2>&1"
def buildCmd = "${sourceCall}; ${buildCall}"
def bitbakeStatus = 0;
sshagent (credentials: [env.SSH_ID]) {
def gitCredentials = getGitCredentialID()
sshagent (credentials: [gitCredentials]) {
bitbakeStatus = sh(returnStatus: true, script: "bash -c '${buildCmd}'")
}
println "bitbakeStatus=${bitbakeStatus}"