Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions vars/commitPragmaTrusted.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,21 @@
* config['pragma'] Pragma to get the value of
* config['def_val'] Value to return if not found
*/

import java.util.regex.Pattern

def call(Map config = [:]) {

def def_value = ''
if (config['def_val']) {
def_value = config['def_val']
}
def value = sh(script: '''b=$(git show -s --format=%B |
sed -ne 's/^''' + config['pragma'] +
''': *\\(.*\\)/\\1/p')
if [ -n "$b" ]; then
echo "$b"
else
echo "''' + def_value + '''"
fi''',
returnStdout: true)
return value.trim()
msg = getFinalCommitComment()
try {
def (_,val) = (msg =~ /(?mi)^${config['pragma']}:\s*(.+)$/)[0]
return val
} catch (java.lang.IndexOutOfBoundsException e) {
return def_value
}

}
}
36 changes: 36 additions & 0 deletions vars/getFinalCommitComment.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// vars/getFinalCommitComment.groovy

/**
* Return the Comment of the last git commit
*
* This needs to be here rather than in pipeline-lib or Jenkinsfile due to
* Scripts not permitted to use method hudson.plugins.git.GitChangeSet getComment
*/
String call(Map config = [:]) {

if (true || config['debug']){
println("checking currentBuild.changeSets")

String comment = "Not found"
if (currentBuild.changeSets != null) {
println("There are " + currentBuild.changeSets.size() + " changeSets")
for (changeSetList in currentBuild.changeSets) {
println("----- changeSetList -----")
println("There are " + changeSetList.size() + " changeSetLists")
for (changeSet in changeSetList) {
println("----- changeSet -----")
println(changeSet.comment)
comment = changeSet.comment
}
}
} else {
println("currentBuild.changeSets was null")
}
}

def changeSetList = currentBuild.changeSets[currentBuild.changeSets.size() - 1]
def changeSet = changeSetList[changeSetList.size() - 1]

return changeSet.comment

}