How to get handle to admin user?

Hopefully this question isn't too dumb - my Java/Spring experience is pretty much nil. : )

I have written a very basic plugin to automatically authorize and enable a build agent when it registers with the server. I did some simple tests to verify that I had all the plumbing in place, and now I'm actually writing the code I need.

I've gotten as far as the code below, but I'm curious how I can get a handle to an SUser object to pass to the "setEnabled" and "setAuthorized" methods, respectively. The offending code is highlighted in bold below. Any help that can be offered would be much appreciated!

import jetbrains.buildServer.serverSide.BuildServerAdapter;
import jetbrains.buildServer.serverSide.SBuildServer;
import jetbrains.buildServer.serverSide.SBuildAgent;
import jetbrains.buildServer.users.SUser;

class BuildAgentAutoAuthorize extends BuildServerAdapter {
    private boolean authorizeAndOrEnableAgent = true;
    public BuildAgentAutoAuthorize(SBuildServer buildServer) {
    public void agentRegistered(SBuildAgent agent, long currentlyRunningBuildId) {
        System.out.println("Agent Registered with server - enabling and authorizing.");
        SUser user = needToGetSUserObjectHereSomeHow();
        if(!agent.isEnabled()) {
            agent.setEnabled(authorizeAndOrEnableAgent, user, "Automatically enabled by TeamCity plugin.");
        if(!agent.isAuthorized()) {
            agent.setAuthorized(authorizeAndOrEnableAgent, user, "Automatically authorized by TeamCity plugin.");
        System.out.println("Finished enabling and authorizing.");


These methods can accept null instead of user object. This means that enabling or authorization is done by the system, not by a user.


Thanks Pavel! Worked perfectly.


Please sign in to leave a comment.