Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
JENKINS-35365 EMail-Ext Extended Pipeline Support - Recipient Providers
- Loading branch information
1 parent
0ad6339
commit e6ed1ee
Showing
16 changed files
with
427 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
src/main/java/hudson/plugins/emailext/EmailExtRecipientStep.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
package hudson.plugins.emailext; | ||
|
||
import hudson.EnvVars; | ||
import hudson.Extension; | ||
import hudson.model.Run; | ||
import hudson.model.TaskListener; | ||
import hudson.plugins.emailext.plugins.RecipientProvider; | ||
import hudson.plugins.emailext.plugins.RecipientProviderDescriptor; | ||
import org.jenkinsci.plugins.workflow.steps.AbstractStepDescriptorImpl; | ||
import org.jenkinsci.plugins.workflow.steps.AbstractStepImpl; | ||
import org.jenkinsci.plugins.workflow.steps.AbstractSynchronousNonBlockingStepExecution; | ||
import org.jenkinsci.plugins.workflow.steps.StepContextParameter; | ||
import org.kohsuke.stapler.DataBoundConstructor; | ||
|
||
import javax.inject.Inject; | ||
import javax.mail.internet.InternetAddress; | ||
import java.util.HashSet; | ||
import java.util.Iterator; | ||
import java.util.List; | ||
import java.util.Set; | ||
|
||
public class EmailExtRecipientStep extends AbstractStepImpl { | ||
private List<RecipientProvider> recipientProviders; | ||
|
||
@DataBoundConstructor | ||
public EmailExtRecipientStep(List<RecipientProvider> recipientProviders) { | ||
this.recipientProviders = recipientProviders; | ||
} | ||
|
||
public List<RecipientProvider> getRecipientProviders() { | ||
return recipientProviders; | ||
} | ||
|
||
public static class Executor extends AbstractSynchronousNonBlockingStepExecution<String> { | ||
private static final long serialVersionUID = 1L; | ||
|
||
@Inject | ||
private transient EmailExtRecipientStep step; | ||
|
||
@StepContextParameter | ||
private transient Run<?, ?> run; | ||
|
||
@StepContextParameter | ||
private transient TaskListener listener; | ||
|
||
@StepContextParameter | ||
private transient EnvVars env; | ||
|
||
@Override | ||
protected String run() throws Exception { | ||
ExtendedEmailPublisher publisher = new ExtendedEmailPublisher(); | ||
ExtendedEmailPublisherContext context = new ExtendedEmailPublisherContext(publisher, run, null, null, listener); | ||
Set<InternetAddress> to = new HashSet<>(); | ||
for (RecipientProvider provider : step.recipientProviders) { | ||
provider.addRecipients(context, env, to, to, to); | ||
} | ||
|
||
StringBuilder rt = new StringBuilder(); | ||
|
||
Iterator<InternetAddress> iterator = to.iterator(); | ||
while (iterator.hasNext()) { | ||
rt.append(iterator.next().toString()); | ||
if (iterator.hasNext()) { | ||
rt.append(" "); | ||
} | ||
} | ||
|
||
return rt.toString(); | ||
} | ||
} | ||
|
||
@Extension(optional = true) | ||
public static final class DescriptorImpl extends AbstractStepDescriptorImpl { | ||
public DescriptorImpl() { | ||
super(Executor.class); | ||
} | ||
|
||
@Override | ||
public String getFunctionName() { | ||
return "emailextrecipients"; | ||
} | ||
|
||
@Override | ||
public String getDisplayName() { | ||
return "Extended Email Recipients"; | ||
} | ||
|
||
@SuppressWarnings("unused") | ||
public List<RecipientProviderDescriptor> getRecipientProvidersDescriptors() { | ||
return RecipientProvider.allSupporting("org.jenkinsci.plugins.workflow.job.WorkflowJob"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.