Title: Message Title
Oleg Stepura commented on JENKINS-26354
Re: First time build does not show changelog
Hi! Thanks for quick reply and sorry I did not react as fast. I discussed internally if this is acceptable to do what you suggested and it was not, but another option to workaround the limitations here was found: JENKINS-54285 I tried using commands from that ticket, it works if we use big enough shallow clone depth (I set it to 100). the only issue I faced was being unable to use sh in a function. It looks buggy. Seems like I cannot simply define a function like this:
def getLastCommitHash() {
return sh(
returnStdout: true,
script: "git show -s --no-abbrev-commit --pretty=format:%P%n%H%n HEAD"
).trim().split("\n").last().trim()
}
and the use it:
def otherFunction() {
def lastCommit = getLastCommitHash()
// do something else with it expecting lastCommit has one-line string
return [a, b, c]
}
In the example above otherFunction() will return exact unprocessed output of sh command from getLastCommitHash() function. This is weird. I was able to workaround this creating simple functions which only run sh commands and do no post-processing (just return sh output) and other functions that only work with strings and not do anything with sh. Then all those functions are used together inside our main node {} context.
def getHeads() {
return sh(
returnStdout: true,
script: "git show -s --no-abbrev-commit --pretty=format:%P%n%H%n HEAD"
)
}
def getLastCommitHash(headsOutput) {
return headsOutput.trim().split("\n").last().trim()
}
then use this in Jenkinsfile:
node("xxx") {
def headsOutput = getHeads()
def lastCommitHash = getLastCommitHash(headsOutput)
// ...
}