Hi, there
Is there a way to get the latest patchset commit message when a event is triggered?
Current Gerrit Trigger Events:
- PatchSet Created
- Draft Published
Here is my trial:
- Using the Jenkinsfile: Only get the lastest merged commit message
pipeline {
agent any
stages {
stage('SCM') {
steps {
// Please note that
// 'checkout scm' is only available
// when using "Multibranch Pipeline" or "Pipeline script from SCM"
checkout scm
}
}
stage('Conventional Analysis') {
steps {
script {
def commitMessage = sh(returnStdout: true, script: 'git log -1 --pretty=%B').trim()
def match = (commitMessage =~ /^(build|chore|ci|docs|feat|fix|perf|refactor|revert|style|test)(\([a-z]+\))?:\s.+$/)
if (!match) {
echo "Non-Conventional Commit: ${commitMessage}"
error("Commit message does not follow conventional commit format")
} else {
echo "Conventional Commit: ${commitMessage}"
}
}
}
}
}
}
- Using Pipeline script: changeset.size is always 0
pipeline {
agent any
stages {
stage('Print commit messages') {
steps {
script {
def changeLogSets = currentBuild.changeSets
echo "Size: ${changeLogSets.size()}"
for (int i = 0; i < changeLogSets.size(); i++) {
def entries = changeLogSets[i].items
echo "Length: ${entries.length}"
for (int j = 0; j < entries.length; j++) {
def entry = entries[j]
echo entry.msg
}
}
}
}
}
}
}