code: @Restricted(NoExternalUse.class)
      public static CauseAction getBuildCause(ParameterizedJob job, StaplerRequest req) {
          Cause cause;
          @SuppressWarnings("deprecation")
          hudson.model.BuildAuthorizationToken authToken = job.getAuthToken();
          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 Cause.RemoteCause(req.getRemoteAddr(), causeText);
          } else {
              cause = new Cause.UserIdCause();
          }
          return new CauseAction(cause);
      }
docs: Computes the build cause, using RemoteCause or UserCause as appropriate.