Search in sources :

Example 6 with UserCause

use of hudson.model.Cause.UserCause in project hudson-2.x by hudson.

the class AbstractProject method getBuildCause.

/**
     * Computes the build cause, using RemoteCause or UserCause as appropriate.
     */
/*package*/
CauseAction getBuildCause(StaplerRequest req) {
    Cause cause;
    if (authToken != null && authToken.getToken() != null && req.getParameter("token") != null) {
        // Optional additional cause text when starting via token
        String causeText = req.getParameter("cause");
        cause = new RemoteCause(req.getRemoteAddr(), causeText);
    } else {
        cause = new UserCause();
    }
    return new CauseAction(cause);
}
Also used : UserCause(hudson.model.Cause.UserCause) UserCause(hudson.model.Cause.UserCause) RemoteCause(hudson.model.Cause.RemoteCause) LegacyCodeCause(hudson.model.Cause.LegacyCodeCause) RemoteCause(hudson.model.Cause.RemoteCause)

Example 7 with UserCause

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

the class Promotion method getUserName.

/**
     * Get a user name of the person, who triggered the promotion.
     * The method tries various sources like {@link UserIdCause} or {@link ManualCondition.Badge}.
     * @return user's name who triggered the promotion, or 'anonymous' if the search fails
     */
@Nonnull
public String getUserName() {
    // Deprecated, but we still want to support it in order to maintain the compatiibility
    final UserCause userCause = getCause(UserCause.class);
    final String nameFromUserCause = userCause != null ? userCause.getUserName() : null;
    if (nameFromUserCause != null) {
        return nameFromUserCause;
    }
    // Modern UserIdCause
    final UserIdCause userIdCause = getCause(UserIdCause.class);
    final String nameFromUserIdCause = userIdCause != null ? userIdCause.getUserName() : null;
    if (nameFromUserIdCause != null) {
        return nameFromUserIdCause;
    }
    //fallback to badge lookup for compatibility 
    for (PromotionBadge badget : getStatus().getBadges()) {
        if (badget instanceof ManualCondition.Badge) {
            final String nameFromBadge = ((ManualCondition.Badge) badget).getUserName();
            if (!nameFromBadge.equals(ManualCondition.MISSING_USER_ID_DISPLAY_STRING)) {
                return nameFromBadge;
            }
        }
    }
    return Jenkins.ANONYMOUS.getName();
}
Also used : UserCause(hudson.model.Cause.UserCause) UserIdCause(hudson.model.Cause.UserIdCause) Nonnull(javax.annotation.Nonnull)

Aggregations

UserCause (hudson.model.Cause.UserCause)7 UserIdCause (hudson.model.Cause.UserIdCause)2 Nonnull (javax.annotation.Nonnull)2 HtmlImage (com.gargoylesoftware.htmlunit.html.HtmlImage)1 HtmlPage (com.gargoylesoftware.htmlunit.html.HtmlPage)1 AbortException (hudson.AbortException)1 LegacyCodeCause (hudson.model.Cause.LegacyCodeCause)1 RemoteCause (hudson.model.Cause.RemoteCause)1 FreeStyleBuild (hudson.model.FreeStyleBuild)1 FreeStyleProject (hudson.model.FreeStyleProject)1 ParameterDefinition (hudson.model.ParameterDefinition)1 ParameterValue (hudson.model.ParameterValue)1 User (hudson.model.User)1 ManualCondition (hudson.plugins.promoted_builds.conditions.ManualCondition)1 IOException2 (hudson.util.IOException2)1 IOException (java.io.IOException)1 CheckForNull (javax.annotation.CheckForNull)1 JSONArray (net.sf.json.JSONArray)1 JSONObject (net.sf.json.JSONObject)1