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