use of org.jfrog.build.extractor.clientConfiguration.client.artifactory.ArtifactoryManager in project build-info by JFrogDev.
the class DeployTask method handleBuildInfoDeployment.
private void handleBuildInfoDeployment(ArtifactoryClientConfiguration accRoot, BuildInfo buildInfo, Map<String, Set<DeployDetails>> allDeployDetails) throws IOException {
String contextUrl = accRoot.publisher.getContextUrl();
if (contextUrl != null) {
try (ArtifactoryManager artifactoryManager = new ArtifactoryManager(accRoot.publisher.getContextUrl(), accRoot.publisher.getUsername(), accRoot.publisher.getPassword(), new GradleClientLogger(log))) {
if (isPublishBuildInfo(accRoot)) {
// If export property set always save the file before sending it to artifactory
exportBuildInfo(buildInfo, getExportFile(accRoot));
if (accRoot.info.isIncremental()) {
log.debug("Publishing build info modules to artifactory at: '{}'", contextUrl);
artifactoryManager.sendModuleInfo(buildInfo);
} else {
log.debug("Publishing build info to artifactory at: '{}'", contextUrl);
Utils.sendBuildAndBuildRetention(artifactoryManager, buildInfo, accRoot);
}
}
if (isGenerateDeployableArtifactsToFile(accRoot)) {
try {
exportDeployableArtifacts(allDeployDetails, new File(accRoot.info.getDeployableArtifactsFilePath()), accRoot.info.isBackwardCompatibleDeployableArtifacts());
} catch (Exception e) {
log.error("Failed writing deployable artifacts to file: ", e);
throw new RuntimeException("Failed writing deployable artifacts to file", e);
}
}
}
}
}
use of org.jfrog.build.extractor.clientConfiguration.client.artifactory.ArtifactoryManager in project build-info by JFrogDev.
the class DeployTask method deployArtifacts.
private void deployArtifacts(ArtifactoryClientConfiguration accRoot, Map<String, String> propsRoot, Map<String, Set<DeployDetails>> allDeployDetails, ArtifactoryTask artifactoryTask, String logPrefix) {
try {
if (artifactoryTask.getDidWork()) {
ArtifactoryClientConfiguration.PublisherHandler publisher = ArtifactoryPluginUtil.getPublisherHandler(artifactoryTask.getProject());
if (publisher != null && publisher.getContextUrl() != null) {
Map<String, String> moduleProps = new HashMap<String, String>(propsRoot);
moduleProps.putAll(publisher.getProps());
publisher.getProps().putAll(moduleProps);
String contextUrl = publisher.getContextUrl();
String username = publisher.getUsername();
String password = publisher.getPassword();
if (StringUtils.isBlank(username)) {
username = "";
}
if (StringUtils.isBlank(password)) {
password = "";
}
if (publisher.isPublishArtifacts()) {
try (ArtifactoryManager artifactoryManager = new ArtifactoryManager(contextUrl, username, password, new GradleClientLogger(log))) {
log.debug("Uploading artifacts to Artifactory at '{}'", contextUrl);
IncludeExcludePatterns patterns = new IncludeExcludePatterns(publisher.getIncludePatterns(), publisher.getExcludePatterns());
configureProxy(accRoot, artifactoryManager);
configConnectionTimeout(accRoot, artifactoryManager);
configRetriesParams(accRoot, artifactoryManager);
configInsecureTls(accRoot, artifactoryManager);
deployArtifacts(artifactoryTask.deployDetails, artifactoryManager, patterns, logPrefix, publisher.getMinChecksumDeploySizeKb());
}
}
if (!artifactoryTask.deployDetails.isEmpty()) {
Set<DeployDetails> deployDetailsSet = new LinkedHashSet<>();
for (GradleDeployDetails details : artifactoryTask.deployDetails) {
deployDetailsSet.add(details.getDeployDetails());
}
allDeployDetails.put(artifactoryTask.getProject().getName(), deployDetailsSet);
}
}
} else {
log.debug("Task '{}' did no work", artifactoryTask.getPath());
}
} 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 DockerImage method loadLayers.
private void loadLayers(String manifestPath) throws IOException {
try (ArtifactoryManager artifactoryManager = artifactoryManagerBuilder.build()) {
layers = getLayers(artifactoryManager, manifestPath);
List<DockerLayer> markerLayers = layers.getLayers().stream().filter(layer -> layer.getFileName().endsWith(".marker")).collect(Collectors.toList());
// Transform all marker layers into regular layer.
if (markerLayers.size() > 0) {
for (DockerLayer markerLayer : markerLayers) {
// Get image name without '.marker' suffix.
String imageDigests = StringUtils.removeEnd(markerLayer.getDigest(), ".marker");
String imageName = StringUtils.substringBetween(imageTag, "/", ":");
DockerUtils.downloadMarkerLayer(targetRepo, imageName, imageDigests, artifactoryManager);
}
layers = getLayers(artifactoryManager, manifestPath);
}
}
}
use of org.jfrog.build.extractor.clientConfiguration.client.artifactory.ArtifactoryManager in project build-info by JFrogDev.
the class GoRun method execute.
public BuildInfo execute() {
try (ArtifactoryManager artifactoryClient = (artifactoryManagerBuilder != null ? artifactoryManagerBuilder.build() : null)) {
if (artifactoryClient != null) {
preparePrerequisites(resolutionRepository, artifactoryClient);
setResolverAsGoProxy(artifactoryClient);
}
// We create the GoDriver here as env might had changed.
this.goDriver = new GoDriver(GO_CLIENT_CMD, env, path.toFile(), logger);
// First try to run 'go version' to make sure go is in PATH, and write the output to logger.
goDriver.version(true);
goDriver.runCmd(goCmdArgs, true);
populateModuleAndDeps();
return createBuild();
} catch (Exception e) {
logger.error(e.getMessage(), e);
throw new RuntimeException(e);
}
}
use of org.jfrog.build.extractor.clientConfiguration.client.artifactory.ArtifactoryManager in project build-info by JFrogDev.
the class DockerImage method generateBuildInfoModule.
public Module generateBuildInfoModule(Log logger, DockerUtils.CommandType cmdType) throws IOException, InterruptedException {
try (ArtifactoryManager artifactoryManager = artifactoryManagerBuilder.build()) {
ModuleBuilder moduleBuilder = new ModuleBuilder().type(ModuleType.DOCKER).id(substringAfterLast(imageTag, "/")).repository(targetRepo);
try {
findAndSetManifestFromArtifactory(artifactoryManager, logger, cmdType);
} catch (IOException e) {
// The manifest could not be found in Artifactory.
// Yet, we do not fail the build, but return an empty build-info instead.
// The reason for not failing build is that there's a chance that the image was replaced
// with another image, deployed to the same repo path.
// This can happen if two parallel jobs build the same image. In that case, the build-info
// for this build will be empty.
logger.error("The manifest could not be fetched from Artifactory.");
return moduleBuilder.build();
}
logger.info("Fetching details of published docker layers from Artifactory...");
if (cmdType == DockerUtils.CommandType.Push) {
setDependenciesAndArtifacts(moduleBuilder, artifactoryManager);
} else {
setDependencies(moduleBuilder);
}
setBuildInfoModuleProps(moduleBuilder);
return moduleBuilder.build();
}
}
Aggregations