Search in sources :

Example 1 with Build

use of org.jfrog.build.api.Build in project build-info by JFrogDev.

the class DeployTask method prepareAndDeploy.

/**
 * This method will be activated only at the "end" of the build, when we reached the root project.
 *
 * @throws java.io.IOException In case the deployment fails.
 */
private void prepareAndDeploy() throws IOException {
    ArtifactoryClientConfiguration accRoot = ArtifactoryPluginUtil.getArtifactoryConvention(getProject()).getClientConfig();
    Map<String, String> propsRoot = accRoot.publisher.getProps();
    // Reset the default properties, they may have changed
    GradleArtifactoryClientConfigUpdater.setMissingBuildAttributes(accRoot, getProject().getRootProject());
    Set<GradleDeployDetails> allDeployDetails = Sets.newTreeSet();
    List<ArtifactoryTask> orderedTasks = findArtifactoryPublishTasks(getProject().getGradle().getTaskGraph());
    for (ArtifactoryTask artifactoryTask : orderedTasks) {
        if (artifactoryTask.getDidWork()) {
            ArtifactoryClientConfiguration.PublisherHandler publisher = ArtifactoryPluginUtil.getPublisherHandler(artifactoryTask.getProject());
            if (publisher != null && publisher.getContextUrl() != null) {
                Map<String, String> moduleProps = new HashMap<String, String>(propsRoot);
                moduleProps.putAll(publisher.getProps());
                publisher.getProps().putAll(moduleProps);
                String contextUrl = publisher.getContextUrl();
                String username = publisher.getUsername();
                String password = publisher.getPassword();
                if (StringUtils.isBlank(username)) {
                    username = "";
                }
                if (StringUtils.isBlank(password)) {
                    password = "";
                }
                artifactoryTask.collectDescriptorsAndArtifactsForUpload();
                if (publisher.isPublishArtifacts()) {
                    ArtifactoryBuildInfoClient client = null;
                    try {
                        client = new ArtifactoryBuildInfoClient(contextUrl, username, password, new GradleClientLogger(log));
                        log.debug("Uploading artifacts to Artifactory at '{}'", contextUrl);
                        IncludeExcludePatterns patterns = new IncludeExcludePatterns(publisher.getIncludePatterns(), publisher.getExcludePatterns());
                        configureProxy(accRoot, client);
                        configConnectionTimeout(accRoot, client);
                        configRetriesParams(accRoot, client);
                        deployArtifacts(artifactoryTask.deployDetails, client, patterns);
                    } finally {
                        if (client != null) {
                            client.close();
                        }
                    }
                }
                allDeployDetails.addAll(artifactoryTask.deployDetails);
            }
        } else {
            log.debug("Task '{}' did no work", artifactoryTask.getPath());
        }
    }
    ArtifactoryBuildInfoClient client = null;
    String contextUrl = accRoot.publisher.getContextUrl();
    String username = accRoot.publisher.getUsername();
    String password = accRoot.publisher.getPassword();
    if (contextUrl != null) {
        if (StringUtils.isBlank(username)) {
            username = "";
        }
        if (StringUtils.isBlank(password)) {
            password = "";
        }
        try {
            client = new ArtifactoryBuildInfoClient(accRoot.publisher.getContextUrl(), accRoot.publisher.getUsername(), accRoot.publisher.getPassword(), new GradleClientLogger(log));
            configureProxy(accRoot, client);
            configConnectionTimeout(accRoot, client);
            configRetriesParams(accRoot, client);
            GradleBuildInfoExtractor gbie = new GradleBuildInfoExtractor(accRoot, allDeployDetails);
            Build build = gbie.extract(getProject().getRootProject());
            exportBuildInfo(build, getExportFile(accRoot));
            if (isPublishBuildInfo(accRoot)) {
                // If export property set always save the file before sending it to artifactory
                exportBuildInfo(build, getExportFile(accRoot));
                if (accRoot.info.isIncremental()) {
                    log.debug("Publishing build info modules to artifactory at: '{}'", contextUrl);
                    client.sendModuleInfo(build);
                } else {
                    log.debug("Publishing build info to artifactory at: '{}'", contextUrl);
                    Utils.sendBuildAndBuildRetention(client, build, accRoot);
                }
            }
            if (isGenerateBuildInfoToFile(accRoot)) {
                try {
                    exportBuildInfo(build, new File(accRoot.info.getGeneratedBuildInfoFilePath()));
                } catch (Exception e) {
                    log.error("Failed writing build info to file: ", e);
                    throw new IOException("Failed writing build info to file", e);
                }
            }
            if (isGenerateDeployableArtifactsToFile(accRoot)) {
                try {
                    exportDeployableArtifacts(allDeployDetails, new File(accRoot.info.getDeployableArtifactsFilePath()));
                } catch (Exception e) {
                    log.error("Failed writing deployable artifacts to file: ", e);
                    throw new RuntimeException("Failed writing deployable artifacts to file", e);
                }
            }
        } finally {
            if (client != null) {
                client.close();
            }
        }
    }
}
Also used : ArtifactoryClientConfiguration(org.jfrog.build.extractor.clientConfiguration.ArtifactoryClientConfiguration) GradleClientLogger(org.jfrog.gradle.plugin.artifactory.extractor.GradleClientLogger) IncludeExcludePatterns(org.jfrog.build.extractor.clientConfiguration.IncludeExcludePatterns) IOException(java.io.IOException) GradleDeployDetails(org.jfrog.gradle.plugin.artifactory.extractor.GradleDeployDetails) IOException(java.io.IOException) ArtifactoryBuildInfoClient(org.jfrog.build.extractor.clientConfiguration.client.ArtifactoryBuildInfoClient) GradleBuildInfoExtractor(org.jfrog.gradle.plugin.artifactory.extractor.GradleBuildInfoExtractor) Build(org.jfrog.build.api.Build) File(java.io.File)

Example 2 with Build

use of org.jfrog.build.api.Build in project build-info by JFrogDev.

the class BuildInfoRecorder method sessionEnded.

@Override
public void sessionEnded(ExecutionEvent event) {
    try {
        Build build = extract(event);
        if (build != null) {
            File basedir = event.getSession().getTopLevelProject().getBasedir();
            buildDeploymentHelper.deploy(build, conf, deployableArtifactBuilderMap, projectHasTestFailures, basedir);
        }
        deployableArtifactBuilderMap.clear();
        if (wrappedListener != null) {
            wrappedListener.sessionEnded(event);
        }
    } catch (Throwable t) {
        String message = getClass().getName() + ".sessionEnded() listener has failed: ";
        logger.error(message, t);
        throw new RuntimeException(message, t);
    } finally {
        // This is used in Jenkins jobs
        String propertyFilePath = System.getenv(BuildInfoConfigProperties.PROP_PROPS_FILE);
        if (StringUtils.isBlank(propertyFilePath)) {
            // This is used in the Artifactory maven plugin and Bamboo
            propertyFilePath = conf.getPropertiesFile();
        }
        if (StringUtils.isNotBlank(propertyFilePath)) {
            File file = new File(propertyFilePath);
            if (file.exists()) {
                boolean deleteFailed = !file.delete();
                if (deleteFailed) {
                    logger.warn("Failed to delete properties file with sensitive data: " + propertyFilePath);
                }
            }
        }
    }
}
Also used : Build(org.jfrog.build.api.Build) BuildInfoExtractorUtils.getModuleIdString(org.jfrog.build.extractor.BuildInfoExtractorUtils.getModuleIdString) BuildInfoExtractorUtils.getTypeString(org.jfrog.build.extractor.BuildInfoExtractorUtils.getTypeString)

Aggregations

Build (org.jfrog.build.api.Build)2 File (java.io.File)1 IOException (java.io.IOException)1 BuildInfoExtractorUtils.getModuleIdString (org.jfrog.build.extractor.BuildInfoExtractorUtils.getModuleIdString)1 BuildInfoExtractorUtils.getTypeString (org.jfrog.build.extractor.BuildInfoExtractorUtils.getTypeString)1 ArtifactoryClientConfiguration (org.jfrog.build.extractor.clientConfiguration.ArtifactoryClientConfiguration)1 IncludeExcludePatterns (org.jfrog.build.extractor.clientConfiguration.IncludeExcludePatterns)1 ArtifactoryBuildInfoClient (org.jfrog.build.extractor.clientConfiguration.client.ArtifactoryBuildInfoClient)1 GradleBuildInfoExtractor (org.jfrog.gradle.plugin.artifactory.extractor.GradleBuildInfoExtractor)1 GradleClientLogger (org.jfrog.gradle.plugin.artifactory.extractor.GradleClientLogger)1 GradleDeployDetails (org.jfrog.gradle.plugin.artifactory.extractor.GradleDeployDetails)1