3

I have a problem with my teamcity plugin, I created a new build runner and I tried to execute this buildstep, but I got an error:

No enabled compatible agents for this build configuration. Please register a build agent or tweak build configuration requirements. 


I want to create a http request with this teamcity buildstep. But as I said there is no aviable agent and I don't know why. The serverside is already working, but for the agent side I might have fotgotten something.

My code is as following:

Build runner:

package teamcity.alternativePlugin;

import jetbrains.buildServer.RunBuildException;
import jetbrains.buildServer.agent.*;
import org.jetbrains.annotations.NotNull;

public class myBuildRunner implements AgentBuildRunner {

    private int exitCode;
    private String resultMessage;
    private boolean isFinish;
    private String hostName;
    private String port;
    private String user;
    private String password;
    BuildProgressLogger LOG;

    @NotNull
    @Override
    public BuildProcess createBuildProcess(@NotNull AgentRunningBuild runningBuild, @NotNull BuildRunnerContext context) throws RunBuildException {
        this.clearParameters();
        this.LOG = context.getBuild().getBuildLogger();
        if(new RestClientInvoker().ConnectionTest()){
            this.LOG.message("Connection succeeded");
        }else{
            this.LOG.error("Connection failed");
        }
        return null;
    }


    @NotNull
    @Override
    public AgentBuildRunnerInfo getRunnerInfo() {
        return null;
    }

    private void clearParameters() {
        this.exitCode = 0;
        this.resultMessage = "";
        this.isFinish = false;
        this.hostName = null;
        this.port = null;
        this.user = null;
        this.password = null;
    }

}
<br><br>

Rest client:

package teamcity.alternativePlugin;

public class RestClientInvoker {


    public RestClientInvoker(){

    }

    public static boolean ConnectionTest() {
        String hostName = myConstants.SETTINGS_my_HOST_NAME;
        String username = myConstants.SETTINGS_my_USER_NAME;
        String password = myConstants.SETTINGS_my_PASSWORD;
        TestConnection tescon = new TestConnection(hostName, username, password);
        return tescon.verifyConnection();
    }
}

Test connection:

package teamcity.alternativePlugin;

import com.sun.org.apache.xml.internal.security.utils.Base64;
import org.springframework.http.*;
import org.springframework.web.client.RestTemplate;

public class TestConnection {
    private String server;
    private RestTemplate rest;
    private HttpHeaders headers;
    private HttpStatus status;
    private String credentials;

    public TestConnection(String url, String user, String pass) {
        this.rest = new RestTemplate();
        this.server = url;
        this.credentials = user + ":" + pass;
    }

    public final boolean verifyConnection() {
        try {
            addHeaders();
            HttpEntity<String> requestEntity = new HttpEntity<String>("", headers);

            ResponseEntity<String> responseEntity = rest.exchange(server, HttpMethod.GET, requestEntity, String.class);

            this.setStatus(responseEntity.getStatusCode());
            if (status == HttpStatus.valueOf(200))
                return true;
            return false;
        } catch (Exception e) {
            return false;
        }
    }

    private String createCredentials() {
        String encry = Base64.encode((credentials).getBytes());
        return "Basic " + encry;
    }

    private final void addHeaders() {
        this.headers = new HttpHeaders();
        headers.add("Accept", "application/json");
        headers.add("Authorization", createCredentials());
        //headers.add("Authorization", credentials);
    }

    public HttpStatus getStatus() {
        return status;
    }


    public void setStatus(HttpStatus status) {
        this.status = status;
    }
}

0 Answers0