I've a monorepo with many submodules,everytime a PR is raised on my monrepo to update hashes of the submodule, i need to run a jenkins job to see if the hashes in the source branch of PR are in remote of the submdule.
This to avoid failure while building sub modules(because sometimes people fail to commit their changes to remote, but still update hash)
- Quickest way to do this is to run some commands on parallel
- what will be those commands?
Thank you in advance
git clone <url> --branch $PR_SOURCE_BRANCH --single-branch <somefoldername>
after this??
As suggested by the gentlemen @joanis in the comments, i shifted my focus from git commands to bitbucket rest APIs, and response is quick
node {
//SCM checkout
stage('Perform Hash check') {
cleanWs()
sh "git clone <url> --branch $PR_SOURCE_BRANCH --single-branch <somefoldername>"
dir(<somefoldername>) {
def map = [:]
def commitList = sh( script:"(git submodule status | awk '{ print \$1 \" \" \$2 }')",returnStdout: true).replace("-","").split("\n")
commitList.each {
map[it.split(" ")[0].trim()] = it.split(" ")[1].trim()
}
map.each { commitid, reponame ->
def url = "https://api.bitbucket.org/2.0/repositories/reposlug/$reponame/commits/$commitid"
final def (String response, int code) = sh(script: "curl -s -w '\\n%{response_code}' -u username:app-password $url", returnStdout: true).trim().tokenize("\n")
if (code != 200) {
error()
}
}
}
}
}