I have Jenkins job with active choice parameter with the name Computer. Which groovy script I should write to bring me all the Nodes names, and present only the one for the current logged in user? All nodes are with the label Desktop. I tried the below but it doesn't work:
import hudson.slaves.DumbSlave def users = [] for (DumbSlave it : Hudson.instance.getSlaves()) { if(it.getLabelString().contains("Desktop")) { def currAgent = it?.computer?.name if(currAgent != null) { users.add(currAgent) } } } return users Update (full answer with logged-on user, based on the below answer):
import jenkins.model.* import hudson.model.User def users = [] Jenkins.instance.nodes.each { node -> if(node.labelString.contains("Desktop")) { def currAgent = node?.computer def currAgentName = node?.computer?.name if(currAgentName != null) { def user = currAgent.systemProperties['user.name']?.toLowerCase() if (!users.contains(user) && user==User.current().toString()){ users.add(currAgentName) } } } } return users
def users = []but used it as Mapusers.containsKey..and IMO you should return a List at the end.computer.systemProperties['user.name']