提交 a996e4b2 编写于 作者: K kohsuke

Adding a publisher to deploy artifacts after a build.


git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@7467 71c3de6d-444a-0410-be80-ed276b4c234a
上级 22ba452c
package hudson.maven;
import hudson.maven.MavenModuleSetBuild;
import hudson.maven.MavenEmbedder;
import hudson.maven.MavenUtil;
import hudson.maven.MavenModuleSet;
import hudson.maven.reporters.MavenAbstractArtifactRecord;
import hudson.model.AbstractProject;
import hudson.model.AbstractBuild;
import hudson.model.BuildListener;
import hudson.model.Result;
import hudson.tasks.BuildStepDescriptor;
import hudson.tasks.Publisher;
import hudson.Launcher;
import java.io.IOException;
import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.deployer.ArtifactDeploymentException;
import org.apache.maven.embedder.MavenEmbedderException;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
import org.kohsuke.stapler.DataBoundConstructor;
/**
* {@link Publisher} for {@link MavenModuleSetBuild} to deploy artifacts
* after a build is fully succeeded.
*
* @author Kohsuke Kawaguchi
* @since 1.191
*/
public class RedeployPublisher extends Publisher {
private final String id;
private final String repositoryUrl;
private final boolean uniqueVersion;
@DataBoundConstructor
public RedeployPublisher(String id, String repositoryUrl, boolean uniqueVersion) {
this.id = id;
this.repositoryUrl = repositoryUrl;
this.uniqueVersion = uniqueVersion;
}
public boolean perform(AbstractBuild<?,?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException {
MavenAbstractArtifactRecord mar = getAction(build);
if(mar==null) {
listener.getLogger().println("No artifacts are recorded. Is this a Maven project?");
build.setResult(Result.FAILURE);
return true;
}
try {
MavenEmbedder embedder = MavenUtil.createEmbedder(listener, null);
ArtifactRepositoryLayout layout =
(ArtifactRepositoryLayout) embedder.getContainer().lookup( ArtifactRepositoryLayout.ROLE,"default");
ArtifactRepositoryFactory factory =
(ArtifactRepositoryFactory) embedder.lookup(ArtifactRepositoryFactory.ROLE);
ArtifactRepository repository = factory.createDeploymentArtifactRepository(
id, repositoryUrl, layout, uniqueVersion);
mar.deploy(embedder,repository,listener);
embedder.stop();
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);
return true;
}
/**
* Obtains the {@link MavenAbstractArtifactRecord} that we'll work on.
* <p>
* This allows promoted-builds plugin to reuse the code for delayed deployment.
*/
protected MavenAbstractArtifactRecord getAction(AbstractBuild<?, ?> build) {
return build.getAction(MavenAbstractArtifactRecord.class);
}
public BuildStepDescriptor<Publisher> getDescriptor() {
return DESCRIPTOR;
}
public static final DescriptorImpl DESCRIPTOR = new DescriptorImpl();
public static final class DescriptorImpl extends BuildStepDescriptor<Publisher> {
public DescriptorImpl() {
super(RedeployPublisher.class);
}
public boolean isApplicable(Class<? extends AbstractProject> jobType) {
return jobType==MavenModuleSet.class;
}
public String getDisplayName() {
return "Deploy artifacts to Maven repository";
}
}
}
......@@ -153,9 +153,9 @@ public abstract class MavenAbstractArtifactRecord<T extends AbstractBuild<?,?>>
* Performs a redeployment.
*/
public final void doRedeploy(StaplerRequest req, StaplerResponse rsp,
@QueryParameter("id") final String id,
@QueryParameter("url") final String repositoryUrl,
@QueryParameter("uniqueVersion") final boolean uniqueVersion) throws ServletException, IOException {
@QueryParameter("redeploy.id") final String id,
@QueryParameter("redeploy.url") final String repositoryUrl,
@QueryParameter("redeploy.uniqueVersion") final boolean uniqueVersion) throws ServletException, IOException {
getBuild().checkPermission(REDEPLOY);
File logFile = new File(getBuild().getRootDir(),"maven-deployment."+records.size()+".log");
......
package hudson.tasks;
import hudson.Launcher;
import hudson.maven.RedeployPublisher;
import hudson.model.AbstractBuild;
import hudson.model.AbstractProject;
import hudson.model.Action;
......@@ -116,6 +117,7 @@ public interface BuildStep {
JavadocArchiver.DESCRIPTOR,
JUnitResultArchiver.DescriptorImpl.DESCRIPTOR,
BuildTrigger.DESCRIPTOR,
RedeployPublisher.DESCRIPTOR,
Mailer.DESCRIPTOR
));
......
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form">
<f:entry title="Repository URL">
<f:textbox name="redeploy.url" />
</f:entry>
<f:advanced>
<f:entry title="Repository ID">
<f:textbox name="redeploy.id" />
</f:entry>
<f:entry>
<f:checkbox name="redeploy.uniqueVersion"/>
<label class="attach-previous">Assign unique versions to snapshots</label>
</f:entry>
</f:advanced>
</j:jelly>
\ No newline at end of file
......@@ -23,19 +23,7 @@
</p>
<f:form method="post" action="redeploy">
<f:entry title="Repository URL">
<f:textbox name="url" />
</f:entry>
<f:advanced>
<f:entry title="Repository ID">
<f:textbox name="id" />
</f:entry>
<f:entry>
<f:checkbox name="uniqueVersion"/>
<label class="attach-previous">Assign unique versions to snapshots</label>
</f:entry>
</f:advanced>
<st:include page="/hudson/maven/RedeployPublisher/config.jelly" />
<f:block>
<f:submit value="OK" style="margin-top:1em;" />
</f:block>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册