use of org.jfrog.build.extractor.ci.BuildInfo 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());
Map<String, Set<DeployDetails>> allDeployDetails = new ConcurrentHashMap<>();
List<ArtifactoryTask> orderedTasks = findArtifactoryPublishTasks(getProject().getGradle().getTaskGraph());
int publishForkCount = getPublishForkCount(accRoot);
if (publishForkCount <= 1) {
orderedTasks.forEach(t -> deployArtifacts(accRoot, propsRoot, allDeployDetails, t, null));
} else {
try {
ExecutorService executor = Executors.newFixedThreadPool(publishForkCount);
CompletableFuture<Void> allUploads = CompletableFuture.allOf(orderedTasks.stream().map(t -> CompletableFuture.runAsync(() -> deployArtifacts(accRoot, propsRoot, allDeployDetails, t, "[" + Thread.currentThread().getName() + "]"), executor)).toArray(CompletableFuture[]::new));
allUploads.get();
} catch (InterruptedException | ExecutionException e) {
throw new RuntimeException(e);
}
}
// Extract Build Info.
GradleBuildInfoExtractor gbie = new GradleBuildInfoExtractor(accRoot, moduleInfoFileProducers);
BuildInfo buildInfo = gbie.extract(getProject().getRootProject());
exportBuildInfo(buildInfo, getExportFile(accRoot));
// Export generated.
generateBuildInfoJson(accRoot, buildInfo);
// Handle deployment.
handleBuildInfoDeployment(accRoot, buildInfo, allDeployDetails);
}
use of org.jfrog.build.extractor.ci.BuildInfo in project build-info by JFrogDev.
the class BuildDockerCreator method execute.
@Override
public BuildInfo execute() {
logger.info("Generating build info for: " + imageFile);
try {
List<Module> modules = new ArrayList<>();
List<ImageFileWithDigest> imageFilesWithDigest = imageFileType == ImageFileType.KANIKO ? getKanikoImageFileWithDigests(imageFile) : getJibImageFilesWithDigests(imageFile);
if (imageFilesWithDigest.isEmpty()) {
throw new RuntimeException("No image files found at path '" + imageFile + "'");
}
for (ImageFileWithDigest imageFileWithDigest : imageFilesWithDigest) {
DockerImage image = new DockerImage("", imageFileWithDigest.imageName, imageFileWithDigest.manifestSha256, sourceRepo, artifactoryManagerBuilder, "", "");
Module module = image.generateBuildInfoModule(logger, DockerUtils.CommandType.Push);
if (module.getArtifacts() == null || module.getArtifacts().size() == 0) {
logger.warn("Could not find docker image: " + imageFileWithDigest.imageName + " in Artifactory.");
} else {
setImageLayersProps(image.getLayers(), artifactProperties, artifactoryManagerBuilder);
}
modules.add(module);
logger.info("Successfully created build info for image: " + imageFileWithDigest.imageName);
}
BuildInfo buildInfo = new BuildInfo();
buildInfo.setModules(modules);
return buildInfo;
} catch (Exception e) {
logger.error(ExceptionUtils.getRootCauseMessage(e), e);
throw new RuntimeException(e);
}
}
use of org.jfrog.build.extractor.ci.BuildInfo in project build-info by JFrogDev.
the class DockerPush method execute.
@Override
public BuildInfo execute() {
String message = "Pushing image: " + imageTag;
if (StringUtils.isNotEmpty(host)) {
message += " using docker daemon host: " + host;
}
logger.info(message);
try {
DockerJavaWrapper.pushImage(imageTag, username, password, host, env, logger);
String imageId = DockerJavaWrapper.getImageIdFromTag(imageTag, host, env, logger);
DockerImage image = new DockerImage(imageId, imageTag, "", targetRepository, artifactoryManagerBuilder, "", "");
Module module = image.generateBuildInfoModule(logger, DockerUtils.CommandType.Push);
if (module.getArtifacts() == null || module.getArtifacts().size() == 0) {
logger.warn("Could not find docker image: " + imageTag + " in Artifactory.");
} else {
setImageLayersProps(image.getLayers(), artifactProperties, artifactoryManagerBuilder);
}
BuildInfo buildInfo = new BuildInfo();
modulesList.add(module);
buildInfo.setModules(modulesList);
logger.info("Successfully pushed docker image: " + imageTag);
return buildInfo;
} catch (IOException | InterruptedException e) {
logger.error(e.getMessage(), e);
throw new RuntimeException(e);
}
}
use of org.jfrog.build.extractor.ci.BuildInfo in project build-info by JFrogDev.
the class DockerPull method execute.
@Override
public BuildInfo execute() {
String message = "Pulling image: " + imageTag;
if (StringUtils.isNotEmpty(host)) {
message += " using docker daemon host: " + host;
}
logger.info(message);
try {
DockerJavaWrapper.pullImage(imageTag, username, password, host, env, logger);
String imageId = DockerJavaWrapper.getImageIdFromTag(imageTag, host, env, logger);
Pair<String, String> archDetails = DockerJavaWrapper.getImageArch(imageTag, host, env, logger);
DockerImage image = new DockerImage(imageId, imageTag, "", targetRepository, artifactoryManagerBuilder, archDetails.getLeft(), archDetails.getRight());
Module module = image.generateBuildInfoModule(logger, DockerUtils.CommandType.Pull);
if (module.getDependencies() == null || module.getDependencies().size() == 0) {
logger.warn("Could not find docker image: " + imageTag + " in Artifactory.");
}
BuildInfo buildInfo = new BuildInfo();
modulesList.add(module);
buildInfo.setModules(modulesList);
logger.info("Successfully pulled docker image: " + imageTag);
return buildInfo;
} catch (IOException | InterruptedException e) {
logger.error(e.getMessage(), e);
throw new RuntimeException(e);
}
}
use of org.jfrog.build.extractor.ci.BuildInfo in project build-info by JFrogDev.
the class GradleBuildInfoExtractor method extract.
@Override
public BuildInfo extract(Project rootProject) {
String buildName = clientConf.info.getBuildName();
BuildInfoBuilder bib = new BuildInfoBuilder(buildName);
String buildNumber = clientConf.info.getBuildNumber();
bib.number(buildNumber);
String buildStartedIso = clientConf.info.getBuildStarted();
Date buildStartDate = null;
try {
buildStartDate = new SimpleDateFormat(BuildInfo.STARTED_FORMAT).parse(buildStartedIso);
} catch (ParseException e) {
log.error("Build start date format error: " + buildStartedIso, e);
}
bib.started(buildStartedIso);
BuildAgent buildAgent = new BuildAgent(clientConf.info.getBuildAgentName(), clientConf.info.getBuildAgentVersion());
bib.buildAgent(buildAgent);
// CI agent
String agentName = clientConf.info.getAgentName();
String agentVersion = clientConf.info.getAgentVersion();
if (StringUtils.isNotBlank(agentName) && StringUtils.isNotBlank(agentVersion)) {
bib.agent(new Agent(agentName, agentVersion));
} else {
// Fallback for standalone builds
bib.agent(new Agent(buildAgent.getName(), buildAgent.getVersion()));
}
long durationMillis = buildStartDate != null ? System.currentTimeMillis() - buildStartDate.getTime() : 0;
bib.durationMillis(durationMillis);
Set<File> moduleFilesWithModules = moduleInfoFileProducers.stream().filter(ModuleInfoFileProducer::hasModules).flatMap(moduleInfoFileProducer -> moduleInfoFileProducer.getModuleInfoFiles().getFiles().stream()).collect(Collectors.toSet());
moduleFilesWithModules.forEach(moduleFile -> {
try {
Module module = ModuleExtractorUtils.readModuleFromFile(moduleFile);
List<Artifact> artifacts = module.getArtifacts();
List<Dependency> dependencies = module.getDependencies();
if ((artifacts != null && !artifacts.isEmpty()) || (dependencies != null && !dependencies.isEmpty())) {
bib.addModule(module);
}
} catch (IOException e) {
throw new RuntimeException("Cannot load module info from file: " + moduleFile.getAbsolutePath(), e);
}
});
String parentName = clientConf.info.getParentBuildName();
String parentNumber = clientConf.info.getParentBuildNumber();
if (parentName != null && parentNumber != null) {
bib.parentName(parentName);
bib.parentNumber(parentNumber);
}
String principal = clientConf.info.getPrincipal();
if (StringUtils.isBlank(principal)) {
principal = System.getProperty("user.name");
}
bib.principal(principal);
String artifactoryPrincipal = clientConf.publisher.getUsername();
if (StringUtils.isBlank(artifactoryPrincipal)) {
artifactoryPrincipal = System.getProperty("user.name");
}
bib.artifactoryPrincipal(artifactoryPrincipal);
String artifactoryPluginVersion = clientConf.info.getArtifactoryPluginVersion();
if (StringUtils.isBlank(artifactoryPluginVersion)) {
artifactoryPluginVersion = "Unknown";
}
bib.artifactoryPluginVersion(artifactoryPluginVersion);
String buildUrl = clientConf.info.getBuildUrl();
if (StringUtils.isNotBlank(buildUrl)) {
bib.url(buildUrl);
}
String vcsRevision = clientConf.info.getVcsRevision();
if (StringUtils.isNotBlank(vcsRevision)) {
bib.vcsRevision(vcsRevision);
}
String vcsUrl = clientConf.info.getVcsUrl();
if (StringUtils.isNotBlank(vcsUrl)) {
bib.vcsUrl(vcsUrl);
}
Vcs vcs = new Vcs(vcsUrl, vcsRevision, clientConf.info.getVcsBranch(), clientConf.info.getVcsMessage());
if (!vcs.isEmpty()) {
bib.vcs(Arrays.asList(vcs));
}
if (clientConf.info.isReleaseEnabled()) {
String stagingRepository = clientConf.publisher.getRepoKey();
String comment = clientConf.info.getReleaseComment();
if (comment == null) {
comment = "";
}
bib.addStatus(new PromotionStatusBuilder(Promotion.STAGED).timestampDate(buildStartDate).comment(comment).repository(stagingRepository).ciUser(principal).user(artifactoryPrincipal).build());
}
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);
}
bib.issues(issues);
}
for (Map.Entry<String, String> runParam : clientConf.info.getRunParameters().entrySet()) {
MatrixParameter matrixParameter = new MatrixParameter(runParam.getKey(), runParam.getValue());
bib.addRunParameters(matrixParameter);
}
log.debug("buildInfoBuilder = " + bib);
// for backward compatibility for Artifactory 2.2.3
BuildInfo buildInfo = bib.build();
if (parentName != null && parentNumber != null) {
buildInfo.setParentBuildId(parentName);
}
PackageManagerUtils.collectEnvIfNeeded(clientConf, buildInfo);
return buildInfo;
}
Aggregations