Last active
July 30, 2019 12:26
-
-
Save or-shachar/d539f1c6fcb0df250222cb86a5b2a339 to your computer and use it in GitHub Desktop.
How to recursively find the userId that triggered the build in Jenkins
This file contains hidden or 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
import net.sf.json.JSONException | |
node { | |
// Just example of how to use the function | |
currentBuild.description = find_trigger_user(currentBuild) | |
} | |
def find_trigger_user(build){ | |
cause = build.buildCauses.getJSONObject(0) | |
try{ | |
return cause.getString("userId") | |
}catch (JSONException e){ | |
println("Not directly triggerred. Checking upstream") | |
} | |
possibleUser = null | |
build.upstreamBuilds.each{ | |
println(build.buildCauses.toString()) | |
possibleUser = find_trigger_user(it) | |
if (possibleUser != null) | |
return | |
} | |
return possibleUser | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment