Skip to content

Instantly share code, notes, and snippets.

@fmarot
Created April 15, 2019 19:59
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 fmarot/c8ad900b866ea1084ed1e34d5291ff9e to your computer and use it in GitHub Desktop.
Save fmarot/c8ad900b866ea1084ed1e34d5291ff9e to your computer and use it in GitHub Desktop.
do not take this code as-is because I just copy-pasted it from an old test and do not really know anymore if it works correctly. It may help though...
def userIdCause = currentBuild.rawBuild.getCause(hudson.model.Cause$UserIdCause)
boolean buildTriggeredManually = (userIdCause != null);
//boolean buildIsNightly = userIdCause.toString().toLowerCase().contains("trigger") || currentBuild.rawBuild.getCauses().get(0).toString().contains("BranchIndexingCause")
def buildIsNightly = false
currentBuild.upstreamBuilds?.each { b ->
echo "Upstream build: ${b.getFullDisplayName()}"
buildIsNightly = true
}
//def specificCause = currentBuild.rawBuild.getCause(hudson.model.Cause$UserIdCause) // must be set to null once used because it is not serializable
echo "userIdCause = ${userIdCause}, buildTriggeredManually = ${buildTriggeredManually}, buildIsNightly = ${buildIsNightly}" // #debug
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment