Search in sources :

Example 1 with ArtifactoryManager

use of org.jfrog.build.extractor.clientConfiguration.client.artifactory.ArtifactoryManager in project build-info by JFrogDev.

the class BuildDeploymentHelper method publishBuildInfo.

private void publishBuildInfo(ArtifactoryClientConfiguration clientConf, BuildInfo buildInfo) {
    try (ArtifactoryManager artifactoryManager = artifactoryManagerBuilder.resolveProperties(clientConf)) {
        logger.info("Artifactory Build Info Recorder: Deploying build info ...");
        Utils.sendBuildAndBuildRetention(artifactoryManager, buildInfo, clientConf);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : ArtifactoryManager(org.jfrog.build.extractor.clientConfiguration.client.artifactory.ArtifactoryManager) IOException(java.io.IOException)

Example 2 with ArtifactoryManager

use of org.jfrog.build.extractor.clientConfiguration.client.artifactory.ArtifactoryManager in project build-info by JFrogDev.

the class BuildDeploymentHelper method deploy.

public void deploy(BuildInfo buildInfo, ArtifactoryClientConfiguration clientConf, Map<String, DeployDetails> deployableArtifactBuilders, boolean wereThereTestFailures, File basedir) {
    Map<String, Set<DeployDetails>> deployableArtifactsByModule = prepareDeployableArtifacts(buildInfo, deployableArtifactBuilders);
    logger.debug("Build Info Recorder: deploy artifacts: " + clientConf.publisher.isPublishArtifacts());
    logger.debug("Build Info Recorder: publication fork count: " + clientConf.publisher.getPublishForkCount());
    logger.debug("Build Info Recorder: publish build info: " + clientConf.publisher.isPublishBuildInfo());
    if (!StringUtils.isEmpty(clientConf.info.getGeneratedBuildInfoFilePath())) {
        try {
            BuildInfoExtractorUtils.saveBuildInfoToFile(buildInfo, new File(clientConf.info.getGeneratedBuildInfoFilePath()));
        } catch (Exception e) {
            logger.error("Failed writing build info to file: ", e);
            throw new RuntimeException("Failed writing build info to file", e);
        }
    }
    if (isDeployArtifacts(clientConf, wereThereTestFailures, deployableArtifactsByModule)) {
        try (ArtifactoryManager artifactoryManager = artifactoryManagerBuilder.resolveProperties(clientConf)) {
            new ModuleParallelDeployHelper().deployArtifacts(artifactoryManager, deployableArtifactsByModule, clientConf.publisher.getPublishForkCount());
        }
    }
    if (!StringUtils.isEmpty(clientConf.info.getDeployableArtifactsFilePath())) {
        try {
            DeployableArtifactsUtils.saveDeployableArtifactsToFile(deployableArtifactsByModule, new File(clientConf.info.getDeployableArtifactsFilePath()), false);
        } catch (Exception e) {
            logger.error("Failed writing deployable artifacts to file: ", e);
            throw new RuntimeException("Failed writing deployable artifacts to file", e);
        }
    }
    if (isPublishBuildInfo(clientConf, wereThereTestFailures)) {
        publishBuildInfo(clientConf, buildInfo);
    }
}
Also used : ArtifactoryManager(org.jfrog.build.extractor.clientConfiguration.client.artifactory.ArtifactoryManager) ModuleParallelDeployHelper(org.jfrog.build.extractor.ModuleParallelDeployHelper) File(java.io.File) IOException(java.io.IOException)

Example 3 with ArtifactoryManager

use of org.jfrog.build.extractor.clientConfiguration.client.artifactory.ArtifactoryManager in project build-info by JFrogDev.

the class DistributeBuildTask method distributeBuild.

@TaskAction
public void distributeBuild() throws IOException {
    validate();
    ArtifactoryPluginConvention convention = (ArtifactoryPluginConvention) getProject().getConvention().getPlugins().get("artifactory");
    DistributerConfig distributerConfig = convention.getDistributerConfig();
    ArtifactoryClientConfiguration clientConf = convention.getClientConfig();
    String buildName = distributerConfig.getBuildName();
    String buildNumber = distributerConfig.getBuildNumber();
    buildName = buildName == null ? clientConf.info.getBuildName() : buildName;
    buildNumber = buildNumber == null ? clientConf.info.getBuildNumber() : buildNumber;
    Distribution distribution = new Distribution(distributerConfig.getPublish(), distributerConfig.getOverrideExistingFiles(), distributerConfig.getGpgPassphrase(), distributerConfig.getAsync(), distributerConfig.getTargetRepoKey(), new ArrayList<>(distributerConfig.getSourceRepoKeys()), distributerConfig.getDryRun());
    try (ArtifactoryManager artifactoryManager = new ArtifactoryManager(distributerConfig.getContextUrl(), distributerConfig.getUsername(), distributerConfig.getPassword(), new GradleClientLogger(getLogger()))) {
        artifactoryManager.distributeBuild(buildName, buildNumber, distribution);
        log.info(String.format("Successfully distributed build %s/%s", clientConf.info.getBuildName(), clientConf.info.getBuildNumber()));
    }
}
Also used : ArtifactoryClientConfiguration(org.jfrog.build.extractor.clientConfiguration.ArtifactoryClientConfiguration) GradleClientLogger(org.jfrog.gradle.plugin.artifactory.extractor.GradleClientLogger) ArtifactoryPluginConvention(org.jfrog.gradle.plugin.artifactory.dsl.ArtifactoryPluginConvention) ArtifactoryManager(org.jfrog.build.extractor.clientConfiguration.client.artifactory.ArtifactoryManager) Distribution(org.jfrog.build.api.release.Distribution) DistributerConfig(org.jfrog.gradle.plugin.artifactory.dsl.DistributerConfig) TaskAction(org.gradle.api.tasks.TaskAction)

Example 4 with ArtifactoryManager

use of org.jfrog.build.extractor.clientConfiguration.client.artifactory.ArtifactoryManager in project build-info by JFrogDev.

the class ArtifactoryBuildListener method doDeploy.

private void doDeploy(BuildEvent event) {
    IvyBuildInfoLog log = getBuildInfoLog(event);
    log.info("[buildinfo:ant] Starting deployment");
    Project project = event.getProject();
    Set<DeployDetails> deployDetails = ctx.getDeployDetails();
    BuildInfoBuilder builder = new BuildInfoBuilder(project.getName()).modules(ctx.getModules()).number("0").durationMillis(System.currentTimeMillis() - ctx.getBuildStartTime()).startedDate(new Date(ctx.getBuildStartTime())).buildAgent(new BuildAgent("Ivy", Ivy.getIvyVersion())).agent(new Agent("Ivy", Ivy.getIvyVersion()));
    ArtifactoryClientConfiguration clientConf = ctx.getClientConf();
    String agentName = clientConf.info.getAgentName();
    String agentVersion = clientConf.info.getAgentVersion();
    if (StringUtils.isNotBlank(agentName) && StringUtils.isNotBlank(agentVersion)) {
        builder.agent(new Agent(agentName, agentVersion));
    }
    String buildAgentName = clientConf.info.getBuildAgentName();
    String buildAgentVersion = clientConf.info.getBuildAgentVersion();
    if (StringUtils.isNotBlank(buildAgentName) && StringUtils.isNotBlank(buildAgentVersion)) {
        builder.buildAgent(new BuildAgent(buildAgentName, buildAgentVersion));
    }
    String buildName = clientConf.info.getBuildName();
    if (StringUtils.isNotBlank(buildName)) {
        builder.name(buildName);
    }
    String buildNumber = clientConf.info.getBuildNumber();
    if (StringUtils.isNotBlank(buildNumber)) {
        builder.number(buildNumber);
    }
    String buildUrl = clientConf.info.getBuildUrl();
    if (StringUtils.isNotBlank(buildUrl)) {
        builder.url(buildUrl);
    }
    String vcsRevision = clientConf.info.getVcsRevision();
    if (StringUtils.isNotBlank(vcsRevision)) {
        builder.vcsRevision(vcsRevision);
    }
    String vcsUrl = clientConf.info.getVcsUrl();
    if (StringUtils.isNotBlank(vcsUrl)) {
        builder.vcsUrl(vcsUrl);
    }
    Vcs vcs = new Vcs(vcsUrl, vcsRevision, clientConf.info.getVcsBranch(), clientConf.info.getVcsMessage());
    if (!vcs.isEmpty()) {
        builder.vcs(Arrays.asList(vcs));
    }
    String artifactoryPluginVersion = clientConf.info.getArtifactoryPluginVersion();
    if (StringUtils.isNotBlank(artifactoryPluginVersion)) {
        builder.artifactoryPluginVersion(artifactoryPluginVersion);
    } else {
        builder.artifactoryPluginVersion("Unknown");
    }
    String principal = clientConf.info.getPrincipal();
    if (StringUtils.isNotBlank(principal)) {
        builder.principal(principal);
    }
    String parentBuildName = clientConf.info.getParentBuildName();
    if (StringUtils.isNotBlank(parentBuildName)) {
        builder.parentName(parentBuildName);
    }
    String parentBuildNumber = clientConf.info.getParentBuildNumber();
    if (StringUtils.isNotBlank(parentBuildNumber)) {
        builder.parentNumber(parentBuildNumber);
    }
    String issueTrackerName = clientConf.info.issues.getIssueTrackerName();
    if (StringUtils.isNotBlank(issueTrackerName)) {
        Issues issues = new Issues();
        issues.setAggregateBuildIssues(clientConf.info.issues.getAggregateBuildIssues());
        issues.setAggregationBuildStatus(clientConf.info.issues.getAggregationBuildStatus());
        issues.setTracker(new IssueTracker(issueTrackerName, clientConf.info.issues.getIssueTrackerVersion()));
        Set<Issue> affectedIssuesSet = clientConf.info.issues.getAffectedIssuesSet();
        if (!affectedIssuesSet.isEmpty()) {
            issues.setAffectedIssues(affectedIssuesSet);
        }
        builder.issues(issues);
    }
    for (Map.Entry<String, String> runParam : clientConf.info.getRunParameters().entrySet()) {
        MatrixParameter matrixParameter = new MatrixParameter(runParam.getKey(), runParam.getValue());
        builder.addRunParameters(matrixParameter);
    }
    BuildInfo buildInfo = builder.build();
    PackageManagerUtils.collectEnvIfNeeded(clientConf, buildInfo);
    String contextUrl = clientConf.publisher.getContextUrl();
    String username = clientConf.publisher.getUsername();
    String password = clientConf.publisher.getPassword();
    try (ArtifactoryManager artifactoryManager = new ArtifactoryManager(contextUrl, username, password, log)) {
        configureProxy(clientConf, artifactoryManager);
        configConnectionTimeout(clientConf, artifactoryManager);
        configRetriesParams(clientConf, artifactoryManager);
        if (clientConf.publisher.isPublishArtifacts()) {
            IncludeExcludePatterns patterns = new IncludeExcludePatterns(clientConf.publisher.getIncludePatterns(), clientConf.publisher.getExcludePatterns());
            deployArtifacts(project, artifactoryManager, deployDetails, patterns);
        }
        if (clientConf.publisher.isPublishBuildInfo()) {
            Utils.sendBuildAndBuildRetention(artifactoryManager, buildInfo, clientConf);
        }
        isDidDeploy = true;
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : ArtifactoryClientConfiguration(org.jfrog.build.extractor.clientConfiguration.ArtifactoryClientConfiguration) Agent(org.jfrog.build.extractor.ci.Agent) BuildAgent(org.jfrog.build.extractor.ci.BuildAgent) DeployDetails(org.jfrog.build.extractor.clientConfiguration.deploy.DeployDetails) Issue(org.jfrog.build.extractor.ci.Issue) Issues(org.jfrog.build.extractor.ci.Issues) IssueTracker(org.jfrog.build.extractor.ci.IssueTracker) MatrixParameter(org.jfrog.build.extractor.ci.MatrixParameter) Vcs(org.jfrog.build.extractor.ci.Vcs) IncludeExcludePatterns(org.jfrog.build.extractor.clientConfiguration.IncludeExcludePatterns) IOException(java.io.IOException) BuildAgent(org.jfrog.build.extractor.ci.BuildAgent) Date(java.util.Date) Project(org.apache.tools.ant.Project) BuildInfoBuilder(org.jfrog.build.extractor.builder.BuildInfoBuilder) ArtifactoryManager(org.jfrog.build.extractor.clientConfiguration.client.artifactory.ArtifactoryManager) BuildInfo(org.jfrog.build.extractor.ci.BuildInfo) IvyBuildInfoLog(org.jfrog.build.util.IvyBuildInfoLog) Map(java.util.Map)

Example 5 with ArtifactoryManager

use of org.jfrog.build.extractor.clientConfiguration.client.artifactory.ArtifactoryManager in project build-info by JFrogDev.

the class NpmBuildInfoExtractor method populateDependenciesMap.

/**
 * Populate the dependencies map for the specified scope by:
 * 1. Create npm dependency tree from root node of 'npm ls' command tree. Populate each node with name, version and scope.
 * 2. For each dependency, retrieve sha1 and md5 from Artifactory. Use the producer-consumer mechanism to parallelize it.
 */
private void populateDependenciesMap(Map<String, Dependency> dependencies, Map<String, Dependency> previousBuildDependencies, JsonNode npmDependencyTree, NpmScope scope, Path workingDir) throws Exception {
    // Set of packages that could not be found in Artifactory.
    Set<NpmPackageInfo> badPackages = Collections.synchronizedSet(new HashSet<>());
    DefaultMutableTreeNode rootNode = NpmDependencyTree.createDependencyTree(npmDependencyTree, scope, workingDir);
    try (ArtifactoryManager artifactoryManager = artifactoryManagerBuilder.build()) {
        // Create producer Runnable.
        ProducerRunnableBase[] producerRunnable = new ProducerRunnableBase[] { new NpmExtractorProducer(rootNode) };
        // Create consumer Runnables.
        ConsumerRunnableBase[] consumerRunnables = new ConsumerRunnableBase[] { new NpmExtractorConsumer(artifactoryManager, dependencies, previousBuildDependencies, badPackages), new NpmExtractorConsumer(artifactoryManager, dependencies, previousBuildDependencies, badPackages), new NpmExtractorConsumer(artifactoryManager, dependencies, previousBuildDependencies, badPackages) };
        // Create the deployment executor.
        ProducerConsumerExecutor deploymentExecutor = new ProducerConsumerExecutor(logger, producerRunnable, consumerRunnables, CONNECTION_POOL_SIZE);
        deploymentExecutor.start();
        if (!badPackages.isEmpty()) {
            logger.info((Arrays.toString(badPackages.toArray())));
            logger.info("The npm dependencies above could not be found in Artifactory and therefore are not included in the build-info. " + "Make sure the dependencies are available in Artifactory for this build. " + "Deleting the local cache will force populating Artifactory with these dependencies.");
        }
    }
}
Also used : NpmPackageInfo(org.jfrog.build.extractor.npm.types.NpmPackageInfo) ProducerConsumerExecutor(org.jfrog.build.extractor.producerConsumer.ProducerConsumerExecutor) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) ArtifactoryManager(org.jfrog.build.extractor.clientConfiguration.client.artifactory.ArtifactoryManager) ProducerRunnableBase(org.jfrog.build.extractor.producerConsumer.ProducerRunnableBase) ConsumerRunnableBase(org.jfrog.build.extractor.producerConsumer.ConsumerRunnableBase)

Aggregations

ArtifactoryManager (org.jfrog.build.extractor.clientConfiguration.client.artifactory.ArtifactoryManager)21 IOException (java.io.IOException)11 File (java.io.File)3 ArtifactoryClientConfiguration (org.jfrog.build.extractor.clientConfiguration.ArtifactoryClientConfiguration)3 DeployDetails (org.jfrog.build.extractor.clientConfiguration.deploy.DeployDetails)3 ModuleBuilder (org.jfrog.build.extractor.builder.ModuleBuilder)2 BuildInfo (org.jfrog.build.extractor.ci.BuildInfo)2 IncludeExcludePatterns (org.jfrog.build.extractor.clientConfiguration.IncludeExcludePatterns)2 ConsumerRunnableBase (org.jfrog.build.extractor.producerConsumer.ConsumerRunnableBase)2 ProducerConsumerExecutor (org.jfrog.build.extractor.producerConsumer.ProducerConsumerExecutor)2 ProducerRunnableBase (org.jfrog.build.extractor.producerConsumer.ProducerRunnableBase)2 Serializable (java.io.Serializable)1 java.util (java.util)1 Date (java.util.Date)1 Map (java.util.Map)1 Collectors (java.util.stream.Collectors)1 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)1 StringUtils (org.apache.commons.lang3.StringUtils)1 Pair (org.apache.commons.lang3.tuple.Pair)1 Header (org.apache.http.Header)1