打印了JENKINS节点日志
This commit is contained in:
parent
011e13dbfa
commit
ee9c0124fd
@ -24,13 +24,17 @@ public interface IJenkinsServiceIntegration extends IExternalSystemIntegration {
|
||||
/**
|
||||
* 获取Jenkins Crumb(用于CSRF保护)
|
||||
*
|
||||
* @param externalSystem Jenkins系统配置
|
||||
* @return Crumb响应信息
|
||||
*/
|
||||
JenkinsCrumbIssuerResponse getJenkinsCrumbIssue();
|
||||
JenkinsCrumbIssuerResponse getJenkinsCrumbIssue(ExternalSystem externalSystem);
|
||||
|
||||
/**
|
||||
* 使用参数触发构建
|
||||
*
|
||||
* @param externalSystem Jenkins系统配置
|
||||
* @param jobName 任务名称
|
||||
* @param parameters 构建参数
|
||||
* @return 构建队列ID
|
||||
*/
|
||||
String buildWithParameters(ExternalSystem externalSystem, String jobName, Map<String, String> parameters);
|
||||
@ -38,10 +42,11 @@ public interface IJenkinsServiceIntegration extends IExternalSystemIntegration {
|
||||
/**
|
||||
* 获取队列中的构建信息
|
||||
*
|
||||
* @param queueId 队列ID
|
||||
* @param externalSystem Jenkins系统配置
|
||||
* @param queueId 队列ID
|
||||
* @return 队列构建信息
|
||||
*/
|
||||
JenkinsQueueBuildInfoResponse getQueuedBuildInfo(String queueId);
|
||||
JenkinsQueueBuildInfoResponse getQueuedBuildInfo(ExternalSystem externalSystem, String queueId);
|
||||
|
||||
/**
|
||||
* 获取构建状态
|
||||
|
||||
@ -120,8 +120,7 @@ public class JenkinsServiceIntegrationImpl implements IJenkinsServiceIntegration
|
||||
|
||||
|
||||
@Override
|
||||
public JenkinsCrumbIssuerResponse getJenkinsCrumbIssue() {
|
||||
ExternalSystem externalSystem = systemRepository.findById(1L).orElseThrow(() -> new RuntimeException("没有找到三方系统"));
|
||||
public JenkinsCrumbIssuerResponse getJenkinsCrumbIssue(ExternalSystem externalSystem) {
|
||||
String url = externalSystem.getUrl() + "/crumbIssuer/api/json";
|
||||
HttpHeaders headers = createHeaders(externalSystem);
|
||||
HttpEntity<String> entity = new HttpEntity<>(headers);
|
||||
@ -137,7 +136,7 @@ public class JenkinsServiceIntegrationImpl implements IJenkinsServiceIntegration
|
||||
}
|
||||
|
||||
// 1. 获取Crumb
|
||||
JenkinsCrumbIssuerResponse jenkinsCrumbIssue = getJenkinsCrumbIssue();
|
||||
JenkinsCrumbIssuerResponse jenkinsCrumbIssue = getJenkinsCrumbIssue(externalSystem);
|
||||
|
||||
// 2. 构建URL
|
||||
String url = UriComponentsBuilder.fromHttpUrl(externalSystem.getUrl())
|
||||
@ -184,7 +183,7 @@ public class JenkinsServiceIntegrationImpl implements IJenkinsServiceIntegration
|
||||
private void ensurePipelineScriptParameter(ExternalSystem externalSystem, String jobName) {
|
||||
try {
|
||||
// 获取 Crumb
|
||||
JenkinsCrumbIssuerResponse jenkinsCrumbIssue = getJenkinsCrumbIssue();
|
||||
JenkinsCrumbIssuerResponse jenkinsCrumbIssue = getJenkinsCrumbIssue(externalSystem);
|
||||
|
||||
// 获取Job配置
|
||||
String configUrl = String.format("%s/job/%s/config.xml", externalSystem.getUrl(), jobName);
|
||||
@ -359,8 +358,7 @@ public class JenkinsServiceIntegrationImpl implements IJenkinsServiceIntegration
|
||||
}
|
||||
|
||||
@Override
|
||||
public JenkinsQueueBuildInfoResponse getQueuedBuildInfo(String queueId) {
|
||||
ExternalSystem externalSystem = systemRepository.findById(1L).orElseThrow(() -> new RuntimeException("没有找到三方系统"));
|
||||
public JenkinsQueueBuildInfoResponse getQueuedBuildInfo(ExternalSystem externalSystem, String queueId) {
|
||||
String queueUrl = String.format("%s/queue/item/%s/api/json", externalSystem.getUrl().trim(), queueId);
|
||||
ResponseEntity<Map<String, Object>> response = restTemplate.exchange(queueUrl, HttpMethod.GET, createHttpEntity(externalSystem), new ParameterizedTypeReference<>() {
|
||||
});
|
||||
|
||||
@ -76,7 +76,7 @@ public class JenkinsBuildDelegate extends BaseNodeDelegate<JenkinsBuildInputMapp
|
||||
log.info("Jenkins build queued: queueId={}", queueId);
|
||||
|
||||
// 3. 等待构建从队列中开始
|
||||
JenkinsQueueBuildInfoResponse buildInfo = waitForBuildToStart(queueId);
|
||||
JenkinsQueueBuildInfoResponse buildInfo = waitForBuildToStart(externalSystem, queueId);
|
||||
|
||||
log.info("Jenkins build started: buildNumber={}", buildInfo.getBuildNumber());
|
||||
|
||||
@ -142,11 +142,11 @@ public class JenkinsBuildDelegate extends BaseNodeDelegate<JenkinsBuildInputMapp
|
||||
return outputs;
|
||||
}
|
||||
|
||||
private JenkinsQueueBuildInfoResponse waitForBuildToStart(String queueId) {
|
||||
private JenkinsQueueBuildInfoResponse waitForBuildToStart(ExternalSystem externalSystem, String queueId) {
|
||||
int attempts = 0;
|
||||
while (attempts < MAX_QUEUE_POLLS) {
|
||||
try {
|
||||
JenkinsQueueBuildInfoResponse buildInfo = jenkinsServiceIntegration.getQueuedBuildInfo(queueId);
|
||||
JenkinsQueueBuildInfoResponse buildInfo = jenkinsServiceIntegration.getQueuedBuildInfo(externalSystem, queueId);
|
||||
if (buildInfo != null) {
|
||||
return buildInfo;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user