/** * Deploy an artifact from a particular file. * * @param source the file to deploy * @param artifact the artifact definition * @param deploymentRepository the repository to deploy to * @param localRepository the local repository to install into * @param retryFailedDeploymentCount TODO * @throws ArtifactDeploymentException if an error occurred deploying the artifact */ protected void deploy( File source, Artifact artifact, ArtifactRepository deploymentRepository, ArtifactRepository localRepository, int retryFailedDeploymentCount) throws ArtifactDeploymentException { int retryFailedDeploymentCounter = Math.max(1, Math.min(10, retryFailedDeploymentCount)); ArtifactDeploymentException exception = null; for (int count = 0; count < retryFailedDeploymentCounter; count++) { try { if (count > 0) { getLog() .info( "Retrying deployment attempt " + (count + 1) + " of " + retryFailedDeploymentCounter); } getDeployer().deploy(source, artifact, deploymentRepository, localRepository); exception = null; break; } catch (ArtifactDeploymentException e) { if (count + 1 < retryFailedDeploymentCounter) { getLog().warn("Encountered issue during deployment: " + e.getLocalizedMessage()); getLog().debug(e); } if (exception == null) { exception = e; } } } if (exception != null) { throw exception; } }
public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException { if (build.getResult().isWorseThan(getTreshold())) return true; // build failed. Don't publish List<MavenAbstractArtifactRecord> mavenAbstractArtifactRecords = getActions(build, listener); if (mavenAbstractArtifactRecords == null || mavenAbstractArtifactRecords.isEmpty()) { listener.getLogger().println("[ERROR] No artifacts are recorded. Is this a Maven project?"); build.setResult(Result.FAILURE); return true; } if (build instanceof MavenModuleSetBuild && ((MavenModuleSetBuild) build).getParent().isArchivingDisabled()) { listener .getLogger() .println( "[ERROR] You cannot use the \"Deploy artifacts to Maven repository\" feature if you " + "disabled automatic artifact archiving"); build.setResult(Result.FAILURE); return true; } long startupTime = Calendar.getInstance().getTimeInMillis(); try { MavenEmbedder embedder = createEmbedder(listener, build); ArtifactRepositoryLayout layout = (ArtifactRepositoryLayout) embedder.lookup(ArtifactRepositoryLayout.ROLE, "default"); ArtifactRepositoryFactory factory = (ArtifactRepositoryFactory) embedder.lookup(ArtifactRepositoryFactory.ROLE); ArtifactRepository artifactRepository = null; if (url != null) { // By default we try to get the repository definition from the job configuration artifactRepository = getDeploymentRepository(factory, layout, id, url); } for (MavenAbstractArtifactRecord mavenAbstractArtifactRecord : mavenAbstractArtifactRecords) { if (artifactRepository == null && mavenAbstractArtifactRecord instanceof MavenArtifactRecord) { // If no repository definition is set on the job level we try to take it from the POM MavenArtifactRecord mavenArtifactRecord = (MavenArtifactRecord) mavenAbstractArtifactRecord; artifactRepository = getDeploymentRepository( factory, layout, mavenArtifactRecord.repositoryId, mavenArtifactRecord.repositoryUrl); } if (artifactRepository == null) { listener .getLogger() .println( "[ERROR] No Repository settings defined in the job configuration or distributionManagement of the module."); build.setResult(Result.FAILURE); return true; } mavenAbstractArtifactRecord.deploy(embedder, artifactRepository, listener); } listener .getLogger() .println( "[INFO] Deployment done in " + Util.getTimeSpanString(Calendar.getInstance().getTimeInMillis() - startupTime)); return true; } catch (MavenEmbedderException e) { e.printStackTrace(listener.error(e.getMessage())); } catch (ComponentLookupException e) { e.printStackTrace(listener.error(e.getMessage())); } catch (ArtifactDeploymentException e) { e.printStackTrace(listener.error(e.getMessage())); } // failed build.setResult(Result.FAILURE); listener .getLogger() .println( "[INFO] Deployment failed after " + Util.getTimeSpanString(Calendar.getInstance().getTimeInMillis() - startupTime)); return true; }