Reputation: 1023
I want a Jenkins job to traverse through all commits on a branch in chronological order given a starting commit. I want to run Sonar on all commits on the branch. And Sonar is triggered through Jenkins. Is there an option in Jenkins to achieve this?
It is not an option to invoke sonar from my local machine after checking out commits individually in my workspace.
Upvotes: 1
Views: 812
Reputation: 190
You could create build which uses the branch/commit hash from which to build as a build parameter. Than create another build jobs that runs git log --pretty=oneline head...whaterver_commit | awk '{print $1}'
and takes the commit hashes to trigger the first parameterised job.
Edited:
Here is an pipeline script example that should work:
node('your-jenkins-slave') {
checkout scm
def result = sh (script: "git log --pretty=oneline | awk '{print \$1}'", returnStdout: true)
def hashes = result.split('\n')
for (int i = 0; i < hashes.size(); i++) {
def commitHash = hashes[i]
build job: 'your_job_id', parameters: [[$class: 'StringParameterValue', name: 'BRANCH', value:commitHash]]
}
}
Upvotes: 4