Search in sources :

Example 11 with AbstractProject

use of hudson.model.AbstractProject in project hudson-2.x by hudson.

the class BaseBuildResultMail method createEmptyMail.

/**
     * Creates empty mail.
     *
     * @param build build.
     * @param listener listener.
     * @return empty mail.
     * @throws MessagingException exception if any.
     */
protected MimeMessage createEmptyMail(AbstractBuild<?, ?> build, BuildListener listener) throws MessagingException {
    MimeMessage msg = new HudsonMimeMessage(Mailer.descriptor().createSession());
    // TODO: I'd like to put the URL to the page in here,
    // but how do I obtain that?
    msg.setContent("", "text/plain");
    msg.setFrom(new InternetAddress(Mailer.descriptor().getAdminAddress()));
    msg.setSentDate(new Date());
    Set<InternetAddress> rcp = new LinkedHashSet<InternetAddress>();
    StringTokenizer tokens = new StringTokenizer(getRecipients());
    while (tokens.hasMoreTokens()) {
        String address = tokens.nextToken();
        if (address.startsWith("upstream-individuals:")) {
            // people who made a change in the upstream
            String projectName = address.substring("upstream-individuals:".length());
            AbstractProject up = Hudson.getInstance().getItemByFullName(projectName, AbstractProject.class);
            if (up == null) {
                listener.getLogger().println("No such project exist: " + projectName);
                continue;
            }
            includeCulpritsOf(up, build, listener, rcp);
        } else {
            // ordinary address
            try {
                rcp.add(new InternetAddress(address));
            } catch (AddressException e) {
                // report bad address, but try to send to other addresses
                e.printStackTrace(listener.error(e.getMessage()));
            }
        }
    }
    if (CollectionUtils.isNotEmpty(upstreamProjects)) {
        for (AbstractProject project : upstreamProjects) {
            includeCulpritsOf(project, build, listener, rcp);
        }
    }
    if (sendToIndividuals) {
        Set<User> culprits = build.getCulprits();
        if (debug)
            listener.getLogger().println("Trying to send e-mails to individuals who broke the build. sizeof(culprits)==" + culprits.size());
        rcp.addAll(buildCulpritList(listener, culprits));
    }
    msg.setRecipients(Message.RecipientType.TO, rcp.toArray(new InternetAddress[rcp.size()]));
    AbstractBuild<?, ?> pb = build.getPreviousBuild();
    if (pb != null) {
        MailMessageIdAction b = pb.getAction(MailMessageIdAction.class);
        if (b != null) {
            msg.setHeader("In-Reply-To", b.messageId);
            msg.setHeader("References", b.messageId);
        }
    }
    return msg;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) InternetAddress(javax.mail.internet.InternetAddress) User(hudson.model.User) HudsonMimeMessage(hudson.tasks.HudsonMimeMessage) Date(java.util.Date) MailMessageIdAction(hudson.tasks.MailMessageIdAction) StringTokenizer(java.util.StringTokenizer) MimeMessage(javax.mail.internet.MimeMessage) HudsonMimeMessage(hudson.tasks.HudsonMimeMessage) AddressException(javax.mail.internet.AddressException) AbstractProject(hudson.model.AbstractProject)

Example 12 with AbstractProject

use of hudson.model.AbstractProject in project violations-plugin by jenkinsci.

the class ViolationsReport method getLiveConfig.

/**
     * get the configuration for this job.
     *
     * @return the configuration of the job.
     */
public ViolationsConfig getLiveConfig() {
    AbstractProject<?, ?> abstractProject = build.getProject();
    if (abstractProject instanceof Project) {
        Project project = (Project) abstractProject;
        ViolationsPublisher publisher = (ViolationsPublisher) project.getPublisher(ViolationsPublisher.DESCRIPTOR);
        return publisher == null ? null : publisher.getConfig();
    }
    return null;
}
Also used : Project(hudson.model.Project) AbstractProject(hudson.model.AbstractProject)

Example 13 with AbstractProject

use of hudson.model.AbstractProject in project promoted-builds-plugin by jenkinsci.

the class DownstreamPassCondition method getJobList.

/**
     * 
     * List of downstream jobs that we need to monitor resolving variables.
     * @since 2.33
     * @return never null.
     */
public List<AbstractProject<?, ?>> getJobList(ItemGroup context, EnvVars buildEnvironment) {
    List<AbstractProject<?, ?>> r = new ArrayList<AbstractProject<?, ?>>();
    String expandedJobs = getExpandedJobs(jobs, buildEnvironment);
    if (expandedJobs == null)
        return r;
    for (String name : Util.tokenize(expandedJobs, ",")) {
        AbstractProject job = JenkinsHelper.getInstance().getItem(name.trim(), context, AbstractProject.class);
        if (job != null)
            r.add(job);
    }
    return r;
}
Also used : ArrayList(java.util.ArrayList) AbstractProject(hudson.model.AbstractProject)

Example 14 with AbstractProject

use of hudson.model.AbstractProject in project promoted-builds-plugin by jenkinsci.

the class DownstreamPassCondition method isMet.

@Override
public PromotionBadge isMet(PromotionProcess promotionProcess, AbstractBuild<?, ?> build) {
    Badge badge = new Badge();
    PseudoDownstreamBuilds pdb = build.getAction(PseudoDownstreamBuilds.class);
    EnvVars buildEnvironment = new EnvVars(build.getBuildVariables());
    OUTER: for (AbstractProject<?, ?> j : getJobList(build.getProject().getParent(), buildEnvironment)) {
        for (AbstractBuild<?, ?> b : build.getDownstreamBuilds(j)) {
            if (!b.isBuilding()) {
                Result r = b.getResult();
                if ((r == Result.SUCCESS) || (evenIfUnstable && r == Result.UNSTABLE)) {
                    badge.add(b);
                    continue OUTER;
                }
            }
        }
        if (pdb != null) {
            // if fingerprint doesn't have any, try the pseudo-downstream
            for (AbstractBuild<?, ?> b : pdb.listBuilds(j)) {
                if (!b.isBuilding()) {
                    Result r = b.getResult();
                    if ((r == Result.SUCCESS) || (evenIfUnstable && r == Result.UNSTABLE)) {
                        badge.add(b);
                        continue OUTER;
                    }
                }
            }
        }
        // none of the builds of this job passed.
        return null;
    }
    return badge;
}
Also used : EnvVars(hudson.EnvVars) AbstractBuild(hudson.model.AbstractBuild) PromotionBadge(hudson.plugins.promoted_builds.PromotionBadge) AbstractProject(hudson.model.AbstractProject) Result(hudson.model.Result)

Aggregations

AbstractProject (hudson.model.AbstractProject)14 Hudson (hudson.model.Hudson)4 ArrayList (java.util.ArrayList)3 AbstractBuild (hudson.model.AbstractBuild)2 Run (hudson.model.Run)2 Binding (groovy.lang.Binding)1 GroovyShell (groovy.lang.GroovyShell)1 AbortException (hudson.AbortException)1 DependencyRunner (hudson.DependencyRunner)1 ProjectRunnable (hudson.DependencyRunner.ProjectRunnable)1 EnvVars (hudson.EnvVars)1 PermalinkList (hudson.PermalinkList)1 WorkspaceSnapshot (hudson.WorkspaceSnapshot)1 Action (hudson.model.Action)1 UpstreamCause (hudson.model.Cause.UpstreamCause)1 DependencyGraph (hudson.model.DependencyGraph)1 Dependency (hudson.model.DependencyGraph.Dependency)1 Item (hudson.model.Item)1 Job (hudson.model.Job)1 Permalink (hudson.model.PermalinkProjectAction.Permalink)1