Skip to content

Instantly share code, notes, and snippets.

@vladfau
Created June 18, 2019 02:49
Show Gist options
  • Save vladfau/5f7dabd8d154c5ffb5c3ba36e88e9c53 to your computer and use it in GitHub Desktop.
Save vladfau/5f7dabd8d154c5ffb5c3ba36e88e9c53 to your computer and use it in GitHub Desktop.
Jenkins Active Permissions via LDAP
def userid = User.current().id
def auths = Jenkins.instance.securityRealm.loadUserByUsername(userid)
.authorities.collect{a -> a.authority}
@NonCPS
def collectLDAPS(uid) {
println uid
return Jenkins.instance.securityRealm.loadUserByUsername(uid).authorities.collect{a -> a.authority}
}
def cause = currentBuild.getRawBuild().getCause(hudson.model.Cause.UserIdCause)
if (cause != null) {
def uid = cause.getUserId()
def ldaps = collectLDAPS(uid)
for (int i = 0 ; i < ldaps.size(); i++) {
echo ldaps.getAt(i);
}
}
def cause = new com.cloudbees.jenkins.GitHubPushCause("test");
def causeAction = new hudson.model.CauseAction(cause)
def params = new StringParameterValue('BRANCH', "master")
def paramsAction = new ParametersAction(params)
["Job2", "Job1"].each { x ->
Jenkins.instance.queue.schedule(jenkins.model.Jenkins.instance.getItemByFullName("Projects/X_CICD/STORY123/${x}"), 0, causeAction, paramsAction)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment