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);
}
}
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());
}
}
}
}
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());
}
}
}
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;
}
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);
}
Aggregations