Skip to content

Instantly share code, notes, and snippets.

@ajohnstone
Last active May 21, 2020 21:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ajohnstone/0e04ff0c10ad730c0a2a0f817b1c9580 to your computer and use it in GitHub Desktop.
Save ajohnstone/0e04ff0c10ad730c0a2a0f817b1c9580 to your computer and use it in GitHub Desktop.
@NonCPS
def getAllCauses() {
currentBuild.rawBuild.getCauses().toString()
}
@NonCPS
def isIssueCommentCause() {
def triggerCause = currentBuild.rawBuild.getCause(org.jenkinsci.plugins.pipeline.github.trigger.IssueCommentCause)
if (triggerCause) {
env.TRIGGER_COMMENT=triggerCause.comment
echo("Build was started by ${triggerCause.userLogin}, who wrote: " +
"\"${triggerCause.comment}\", which matches the " +
"\"${triggerCause.triggerPattern}\" trigger pattern.")
} else {
echo('Build was not started by a trigger')
}
}
echo getAllCauses()
isIssueCommentCause();
echo env.TRIGGER_COMMENT
if (env.TRIGGER_COMMENT && env.CHANGE_ID) {
def matcher = env.TRIGGER_COMMENT =~ /\/tf (?<op>\w+) (?<args>.*)/
if( matcher.matches() ) {
def op = matcher.group( 'op' )
switch (op) {
case 'plan':
echo "tf plan andy"
break;
default:
error("operation not supported ${op}")
break;
}
}
pullRequest.comment('matched trigger for comment')
}
for (commitFile in pullRequest.files) {
echo "SHA: ${commitFile.sha} File Name: ${commitFile.filename} Status: ${commitFile.status}"
}
for (commit in pullRequest.commits) {
echo "SHA: ${commit.sha}, Committer: ${commit.committer}, Commit Message: ${commit.message}"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment