Last active
May 21, 2020 21:26
-
-
Save ajohnstone/0e04ff0c10ad730c0a2a0f817b1c9580 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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