我的teamcity插件有问题,我创建了一个新的构建运行器,我试图执行这个buildstep,但是我收到了一个错误:
No enabled compatible agents for this build configuration. Please register a build agent or tweak build configuration requirements.
我想用这个teamcity buildstep创建一个http请求。但正如我所说,没有可用的代理人,我也不知道为什么。服务器端已经在工作,但对于代理方,我可能会有一些想法。
我的代码如下:
建立跑步者:
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>
休息客户:
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();
}
}
测试连接:
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;
}
}