jetbrains.buildServer.agent.AgentRunningBuild Java Examples

The following examples show how to use jetbrains.buildServer.agent.AgentRunningBuild. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: S3SignedUrlFileUploader.java    From teamcity-s3-artifact-storage-plugin with Apache License 2.0 6 votes vote down vote up
@NotNull
private static Map<String, URL> fetchUploadUrlFromServer(@NotNull final HttpClient httpClient,
                                                         @NotNull final AgentRunningBuild build,
                                                         @NotNull final Collection<String> s3ObjectKeys) throws IOException {
  try {
    final PostMethod post = new PostMethod(targetUrl(build));
    post.addRequestHeader("User-Agent", "TeamCity Agent");
    post.setRequestEntity(new StringRequestEntity(S3PreSignUrlHelper.writeS3ObjectKeys(s3ObjectKeys), APPLICATION_XML, UTF_8));
    post.setDoAuthentication(true);
    final String responseBody = HttpClientCloseUtil.executeReleasingConnectionAndReadResponseBody(httpClient, post);
    return S3PreSignUrlHelper.readPreSignUrlMapping(responseBody);
  } catch (HttpClientCloseUtil.HttpErrorCodeException e) {
    LOG.debug("Failed resolving S3 pre-signed URL for build " + build.describe(false) + " . Response code " + e.getResponseCode());
    return Collections.emptyMap();
  }
}
 
Example #2
Source File: AnsibleReportArtifatcsProvider.java    From tc-ansible-runner with MIT License 6 votes vote down vote up
public void beforeBuildFinish(@NotNull final AgentRunningBuild build, @NotNull final BuildFinishedStatus buildStatus) {
    String tmpDirPath = build.getSharedConfigParameters().get(AnsibleRunnerConstants.ARTIFACTS_TMP_DIR_KEY);
    if (tmpDirPath == null) {
        return;
    }
    File tmpDir = new File(tmpDirPath);
    if (tmpDir.exists() && tmpDir.isDirectory()) {
        File[] rawFiles = tmpDir.listFiles();
        if (rawFiles == null || rawFiles.length == 0) {
            build.getBuildLogger().warning("Build defines ansible-run tmp directory but it doesn't contain any files");
        } else {
            generateReport(build, rawFiles);
        }
    } else {
        build.getBuildLogger().warning("Build defines ansible-run tmp directory but it doesn't exist");
    }
}
 
Example #3
Source File: AnsibleOutputListener.java    From tc-ansible-runner with MIT License 6 votes vote down vote up
public AnsibleOutputListener(AgentRunningBuild build, BuildRunnerContext buildRunnerContext, ArtifactsWatcher artifactsWatcher) {
    this.artifactsWatcher = artifactsWatcher;
    this.buildRunnerContext = buildRunnerContext;
    File tmpDir = new File(build.getBuildTempDirectory(), "ansible-run");
    boolean exists = tmpDir.exists(); 
    if (!exists) {
        exists = tmpDir.mkdir();
    }
    if (!exists) {
        LOG.error("Cannot create a directory " + tmpDir.getAbsolutePath() + " for ansible run raw output storage");
        build.getBuildLogger().warning("Cannot create a directory for ansible run raw output storage. Ansible report will not be generated");
    } else {
        String rawFileName = "ansible-run-raw-" + buildRunnerContext.getId() + ".log";
        rawFile = new File(tmpDir, rawFileName);
        try {
            rawFile.createNewFile();
        } catch (IOException e) {
            LOG.error("Cannot create a file " + rawFileName + " for ansible run raw output writing ", e);
            build.getBuildLogger().warning("Cannot create a file for ansible run raw output writing. Ansible report will not be generated");
        }
        build.addSharedConfigParameter(AnsibleRunnerConstants.ARTIFACTS_TMP_DIR_KEY, tmpDir.getAbsolutePath());
    }
}
 
Example #4
Source File: S3SignedUrlFileUploader.java    From teamcity-s3-artifact-storage-plugin with Apache License 2.0 5 votes vote down vote up
@Nullable
private static URL fetchUploadUrlFromServer(@NotNull final HttpClient httpClient, @NotNull final AgentRunningBuild build, @NotNull final String s3ObjectKey) {
  try {
    return fetchUploadUrlFromServer(httpClient, build, Collections.singleton(s3ObjectKey)).get(s3ObjectKey);
  } catch (IOException e) {
    throw new ArtifactPublishingFailedException(e.getMessage(), false, e);
  }
}
 
Example #5
Source File: S3SignedUrlFileUploader.java    From teamcity-s3-artifact-storage-plugin with Apache License 2.0 5 votes vote down vote up
@NotNull
private HttpClient createPooledHttpClient(final AgentRunningBuild build) {
  final int connectionTimeout = build.getAgentConfiguration().getServerConnectionTimeout();
  final HttpClient httpClient = HttpUtil.createHttpClient(connectionTimeout);
  final HttpConnectionManager httpConnectionManager = createMultiThreadedHttpConnectionManager(connectionTimeout);
  httpClient.setHttpConnectionManager(httpConnectionManager);
  return httpClient;
}
 
Example #6
Source File: S3SignedUrlFileUploader.java    From teamcity-s3-artifact-storage-plugin with Apache License 2.0 5 votes vote down vote up
@NotNull
private HttpClient createPooledHttpClientToTCServer(@NotNull final AgentRunningBuild build) {
  final int connectionTimeout = build.getAgentConfiguration().getServerConnectionTimeout();
  final HttpClient httpClient;
  try {
    httpClient = HttpUtil.createHttpClient(connectionTimeout, new URL(targetUrl(build)), new UsernamePasswordCredentials(build.getAccessUser(), build.getAccessCode()));
  } catch (MalformedURLException e) {
    throw new RuntimeException(e);
  }
  final HttpConnectionManager httpConnectionManager = createMultiThreadedHttpConnectionManager(connectionTimeout);
  httpClient.setHttpConnectionManager(httpConnectionManager);
  return httpClient;
}
 
Example #7
Source File: AnsibleReportArtifatcsProvider.java    From tc-ansible-runner with MIT License 5 votes vote down vote up
private void provideArtifacts(List<Playbook> playbooks, AgentRunningBuild build) {
    File tmpReport = new File(build.getBuildTempDirectory(), AnsibleRunnerConstants.ARTIFACTS_JSON_REPORT);
    try {
        tmpReport.createNewFile();
        ReportBuilder.buildJsonReport(playbooks, tmpReport);
        build.getBuildLogger().message("Uploading artifact...");
        artifactsWatcher.addNewArtifactsPath(tmpReport.getAbsolutePath() + "=>" + AnsibleRunnerConstants.ARTIFACTS_BASE_DIR);
    } catch (Exception e) {
        LOG.error("Failed to create a file to write ansible run report", e);
        build.getBuildLogger().warning("Failed to generate report. Check agent logs for more details");
    }
}
 
Example #8
Source File: AllureToolProvider.java    From allure-teamcity with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@NotNull
@Override
public String getPath(@NotNull final String toolName,
                      @NotNull final AgentRunningBuild build,
                      @NotNull final BuildRunnerContext runner) {
    return runner.getRunnerParameters().get(AllureConstants.ALLURE_TOOL_VERSION);
}
 
Example #9
Source File: S3FileUploader.java    From teamcity-s3-artifact-storage-plugin with Apache License 2.0 4 votes vote down vote up
@NotNull
Collection<ArtifactDataInstance> publishFiles(@NotNull final AgentRunningBuild build,
                                              @NotNull final String pathPrefix,
                                              @NotNull final Map<File, String> filesToPublish);
 
Example #10
Source File: S3SignedUrlFileUploader.java    From teamcity-s3-artifact-storage-plugin with Apache License 2.0 4 votes vote down vote up
@NotNull
private static String targetUrl(@NotNull final AgentRunningBuild build) {
  return build.getAgentConfiguration().getServerUrl() + HTTP_AUTH + ARTEFACTS_S3_UPLOAD_PRESIGN_URLS_HTML;
}