Search in sources :

Example 1 with BuildInfo

use of org.jfrog.build.extractor.ci.BuildInfo 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 2 with BuildInfo

use of org.jfrog.build.extractor.ci.BuildInfo in project build-info by JFrogDev.

the class PipExtractorTest method pipInstallTest.

@Test(dataProvider = "pipInstallProvider")
private void pipInstallTest(Project project) {
    try {
        if (!project.allowDirtyEnv) {
            // Copy project files to temp.
            projectDir = TestUtils.createTestProjectTempDir(project.targetDir, project.projectOrigin);
            // Check pip env is clean.
            validateEmptyPipEnv(driver);
        }
        // Run pip-install.
        PipInstall pipInstall = new PipInstall(artifactoryManagerBuilder, virtualRepo, project.args, getLog(), projectDir, env, project.moduleId, getUsername(), getAdminToken(), null);
        BuildInfo buildInfo = pipInstall.execute();
        assertNotNull(buildInfo, "Pip execution returned empty buildInfo.");
        // Validate produced build-info.
        Module module = buildInfo.getModules().get(0);
        assertEquals(module.getType(), "pypi");
        assertEquals(module.getId(), project.moduleId);
        assertEquals(module.getDependencies().size(), project.expectedDependencies);
        if (project.cleanEnvAfterExecution) {
            // Clean environment.
            cleanPipEnv(projectDir);
            FileUtils.deleteQuietly(projectDir.toFile());
        }
    } catch (Exception e) {
        // Clean env in case of exception.
        try {
            cleanPipEnv(projectDir);
        } finally {
            fail(ExceptionUtils.getStackTrace(e));
            if (projectDir != null) {
                FileUtils.deleteQuietly(projectDir.toFile());
            }
        }
    }
}
Also used : BuildInfo(org.jfrog.build.extractor.ci.BuildInfo) Module(org.jfrog.build.extractor.ci.Module) IOException(java.io.IOException) Test(org.testng.annotations.Test)

Example 3 with BuildInfo

use of org.jfrog.build.extractor.ci.BuildInfo in project build-info by JFrogDev.

the class NpmExtractorTest method runNpmTest.

private void runNpmTest(Project project, Dependency[] expectedDependencies, String args, boolean packageJsonPath, boolean isNpmCi) {
    Path projectDir = null;
    try {
        // Prepare.
        projectDir = createProjectDir(project);
        Path path = packageJsonPath ? projectDir.resolve("package.json") : projectDir;
        if (isNpmCi) {
            // Run npm install to generate package-lock.json file.
            new NpmInstallCi(artifactoryManagerBuilder, localRepo1, args, log, path, null, null, null, false, null).execute();
        }
        // Execute command.
        NpmInstallCi buildExecutor;
        if (isNpmCi) {
            buildExecutor = new NpmInstallCi(artifactoryManagerBuilder, localRepo1, args, log, path, null, null, null, true, null);
        } else {
            buildExecutor = new NpmInstallCi(artifactoryManagerBuilder, localRepo1, args, log, path, null, null, null, false, null);
        }
        BuildInfo buildInfo = buildExecutor.execute();
        // Validate.
        assertEquals(buildInfo.getModules().size(), 1);
        Module module = buildInfo.getModules().get(0);
        assertEquals(module.getType(), "npm");
        assertEquals(module.getId(), project.getModuleId());
        assertEqualsNoOrder(module.getDependencies().toArray(), expectedDependencies);
    } catch (Exception e) {
        fail(ExceptionUtils.getStackTrace(e));
    } finally {
        if (projectDir != null) {
            FileUtils.deleteQuietly(projectDir.toFile());
        }
    }
}
Also used : Path(java.nio.file.Path) BuildInfo(org.jfrog.build.extractor.ci.BuildInfo) Module(org.jfrog.build.extractor.ci.Module) IOException(java.io.IOException)

Example 4 with BuildInfo

use of org.jfrog.build.extractor.ci.BuildInfo in project build-info by JFrogDev.

the class PipBuildInfoExtractor method createBuild.

private BuildInfo createBuild(List<Dependency> dependenciesList, String moduleName) {
    Module module = new ModuleBuilder().type(ModuleType.PYPI).id(moduleName).dependencies(dependenciesList).build();
    List<Module> modules = new ArrayList<>();
    modules.add(module);
    BuildInfo buildInfo = new BuildInfo();
    buildInfo.setModules(modules);
    return buildInfo;
}
Also used : ModuleBuilder(org.jfrog.build.extractor.builder.ModuleBuilder) BuildInfo(org.jfrog.build.extractor.ci.BuildInfo) ArrayList(java.util.ArrayList) Module(org.jfrog.build.extractor.ci.Module)

Example 5 with BuildInfo

use of org.jfrog.build.extractor.ci.BuildInfo in project build-info by JFrogDev.

the class PackageManagerExtractor method executeAndSaveBuildInfo.

/**
 * Run build-tool command and save build info to file.
 *
 * @param clientConfiguration - The client configuration.
 * @throws RuntimeException in case of any error.
 */
public void executeAndSaveBuildInfo(ArtifactoryClientConfiguration clientConfiguration) throws RuntimeException {
    // During build extractor's job, temp directories are created. This will make sure 'java.io.tmpdir' property is defined in Unix.
    handleJavaTmpdirProperty();
    BuildInfo buildInfo = execute();
    if (buildInfo == null) {
        return;
    }
    PackageManagerUtils.collectEnvIfNeeded(clientConfiguration, buildInfo);
    saveBuildInfoToFile(clientConfiguration, buildInfo);
}
Also used : BuildInfo(org.jfrog.build.extractor.ci.BuildInfo)

Aggregations

BuildInfo (org.jfrog.build.extractor.ci.BuildInfo)28 Module (org.jfrog.build.extractor.ci.Module)18 IOException (java.io.IOException)11 Path (java.nio.file.Path)6 ModuleBuilder (org.jfrog.build.extractor.builder.ModuleBuilder)6 Test (org.testng.annotations.Test)6 File (java.io.File)3 ArrayList (java.util.ArrayList)3 Date (java.util.Date)3 BuildInfoBuilder (org.jfrog.build.extractor.builder.BuildInfoBuilder)3 Artifact (org.jfrog.build.extractor.ci.Artifact)3 Vcs (org.jfrog.build.extractor.ci.Vcs)3 ArtifactoryClientConfiguration (org.jfrog.build.extractor.clientConfiguration.ArtifactoryClientConfiguration)3 DockerImage (org.jfrog.build.extractor.docker.types.DockerImage)3 Map (java.util.Map)2 BuildInfoExtractorUtils.jsonStringToBuildInfo (org.jfrog.build.extractor.BuildInfoExtractorUtils.jsonStringToBuildInfo)2 Agent (org.jfrog.build.extractor.ci.Agent)2 BuildAgent (org.jfrog.build.extractor.ci.BuildAgent)2 Dependency (org.jfrog.build.extractor.ci.Dependency)2 Issue (org.jfrog.build.extractor.ci.Issue)2