hudson.model.Saveable#jenkins.triggers.SCMTriggerItem源码实例Demo

下面列出了hudson.model.Saveable#jenkins.triggers.SCMTriggerItem 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: gitea-plugin   文件: GiteaWebhookListener.java
/**
 * {@inheritDoc}
 */
@Override
public void onChange(Saveable o, XmlFile file) {
    if (!(o instanceof Item)) {
        // must be an Item
        return;
    }
    SCMTriggerItem item = SCMTriggerItem.SCMTriggerItems.asSCMTriggerItem((Item) o);
    if (item == null) {
        // more specifically must be an SCMTriggerItem
        return;
    }
    SCMTrigger trigger = item.getSCMTrigger();
    if (trigger == null || trigger.isIgnorePostCommitHooks()) {
        // must have the trigger enabled and not opted out of post commit hooks
        return;
    }
    for (SCM scm : item.getSCMs()) {
        if (scm instanceof GitSCM) {
            // we have a winner
            GiteaWebhookListener.register(item, (GitSCM) scm);
        }
    }
}
 
/**
 * Construct a SingleTestFlakyStatsWithRevision object with {@link SingleTestFlakyStats} and
 * build information.
 *
 * @param stats Embedded {@link SingleTestFlakyStats} object
 * @param build The {@link hudson.model.Run} object to get SCM information from.
 */
public SingleTestFlakyStatsWithRevision(SingleTestFlakyStats stats, Run build) {
  this.stats = stats;
  revision = Integer.toString(build.getNumber());

  Job job = build.getParent();
  SCMTriggerItem s = SCMTriggerItem.SCMTriggerItems.asSCMTriggerItem(job);
  if (s != null) {
    ArrayList<SCM> scms = new ArrayList<>(s.getSCMs());
    SCM scm = scms.size() > 0 ? scms.get(0) : null;

    if (scm != null && "hudson.plugins.git.GitSCM".equalsIgnoreCase(scm.getType())) {
      GitSCM gitSCM = (GitSCM) scm;
      BuildData buildData = gitSCM.getBuildData(build);
      if (buildData != null) {
        Revision gitRevision = buildData.getLastBuiltRevision();
        if (gitRevision != null) {
          revision = gitRevision.getSha1String();
        }
      }
    }
  }
}
 
源代码3 项目: gitlab-plugin   文件: BuildStatusAction.java
public void execute(StaplerResponse response) {
    SCMTriggerItem item = SCMTriggerItem.SCMTriggerItems.asSCMTriggerItem(project);
    if (!hasGitSCM(item)) {
        throw HttpResponses.error(409, "The project has no GitSCM configured");
    }
    writeStatusBody(response, build, getStatus(build));
}
 
源代码4 项目: gitlab-plugin   文件: BuildStatusAction.java
private boolean hasGitSCM(SCMTriggerItem item) {
    if (item != null) {
        for (SCM scm : item.getSCMs()) {
            if (scm instanceof GitSCM) {
                return true;
            }
        }
    }
    return false;
}
 
protected Action[] createActions(Job<?, ?> job, H hook) {
    ArrayList<Action> actions = new ArrayList<>();
    actions.add(new CauseAction(new GitLabWebHookCause(retrieveCauseData(hook))));
    try {
        SCMTriggerItem item = SCMTriggerItem.SCMTriggerItems.asSCMTriggerItem(job);
        GitSCM gitSCM = getGitSCM(item);
        actions.add(createRevisionParameter(hook, gitSCM));
    } catch (NoRevisionToBuildException e) {
        LOGGER.log(Level.WARNING, "unknown handled situation, dont know what revision to build for req {0} for job {1}",
                new Object[]{hook, (job != null ? job.getFullName() : null)});
    }
    return actions.toArray(new Action[actions.size()]);
}
 
private GitSCM getGitSCM(SCMTriggerItem item) {
    if (item != null) {
        for (SCM scm : item.getSCMs()) {
            if (scm instanceof GitSCM) {
                return (GitSCM) scm;
            }
        }
    }
    return null;
}
 
源代码7 项目: gitlab-plugin   文件: ProjectLabelsProvider.java
/**
 * Get the URL of the first declared repository in the project configuration.
 * Use this as default source repository url.
 *
 * @return URIish the default value of the source repository url
 * @throws IllegalStateException Project does not use git scm.
 */
private URIish getSourceRepoURLDefault(Job<?, ?> job) {
    SCMTriggerItem item = SCMTriggerItem.SCMTriggerItems.asSCMTriggerItem(job);
    GitSCM gitSCM = getGitSCM(item);
    if (gitSCM == null) {
        LOGGER.log(Level.WARNING, "Could not find GitSCM for project. Project = {1}, next build = {2}",
                array(job.getName(), String.valueOf(job.getNextBuildNumber())));
        throw new IllegalStateException("This project does not use git:" + job.getName());
    }
    return getFirstRepoURL(gitSCM.getRepositories());
}
 
源代码8 项目: gitlab-plugin   文件: ProjectLabelsProvider.java
private GitSCM getGitSCM(SCMTriggerItem item) {
    if (item != null) {
        for (SCM scm : item.getSCMs()) {
            if (scm instanceof GitSCM) {
                return (GitSCM) scm;
            }
        }
    }
    return null;
}
 
源代码9 项目: gitlab-plugin   文件: ProjectBranchesProvider.java
/**
 * Get the URL of the first declared repository in the project configuration.
 * Use this as default source repository url.
 *
 * @return URIish the default value of the source repository url
 * @throws IllegalStateException Project does not use git scm.
 */
private URIish getSourceRepoURLDefault(Job<?, ?> job) {
    SCMTriggerItem item = SCMTriggerItem.SCMTriggerItems.asSCMTriggerItem(job);
    GitSCM gitSCM = getGitSCM(item);
    if (gitSCM == null) {
        LOGGER.log(Level.WARNING, "Could not find GitSCM for project. Project = {1}, next build = {2}",
                array(job.getName(), String.valueOf(job.getNextBuildNumber())));
        throw new IllegalStateException("This project does not use git:" + job.getName());
    }
    return getFirstRepoURL(gitSCM.getRepositories());
}
 
源代码10 项目: gitlab-plugin   文件: ProjectBranchesProvider.java
private GitSCM getGitSCM(SCMTriggerItem item) {
    if (item != null) {
        for (SCM scm : item.getSCMs()) {
            if (scm instanceof GitSCM) {
                return (GitSCM) scm;
            }
        }
    }
    return null;
}
 
源代码11 项目: gogs-webhook-plugin   文件: GogsTrigger.java
@Override
public boolean isApplicable(Item item) {
    return item instanceof Job && SCMTriggerItem.SCMTriggerItems.asSCMTriggerItem(item) != null
            && item instanceof ParameterizedJobMixIn.ParameterizedJob;
}
 
源代码12 项目: gogs-webhook-plugin   文件: GogsPayloadProcessor.java
public GogsResults triggerJobs(String jobName, String deliveryID) {
    SecurityContext saveCtx = ACL.impersonate(ACL.SYSTEM);
    GogsResults result = new GogsResults();

    try {
        BuildableItem project = GogsUtils.find(jobName, BuildableItem.class);
        if (project != null) {
            GogsTrigger gTrigger = null;
            Cause cause = new GogsCause(deliveryID);

            if (project instanceof ParameterizedJobMixIn.ParameterizedJob) {
                ParameterizedJobMixIn.ParameterizedJob pJob = (ParameterizedJobMixIn.ParameterizedJob) project;
                for (Trigger trigger : pJob.getTriggers().values()) {
                    if (trigger instanceof GogsTrigger) {
                        gTrigger = (GogsTrigger) trigger;
                        break;
                    }
                }
            }

            if (gTrigger != null) {
                SCMTriggerItem item = SCMTriggerItem.SCMTriggerItems.asSCMTriggerItem(project);
                GogsPayload gogsPayload = new GogsPayload(this.payload);
                if (item != null) {
                    item.scheduleBuild2(0, gogsPayload);
                }
            } else {
                project.scheduleBuild(0, cause);
            }
            result.setMessage(String.format("Job '%s' is executed", jobName));
        } else {
            String msg = String.format("Job '%s' is not defined in Jenkins", jobName);
            result.setStatus(404, msg);
            LOGGER.warning(msg);
        }
    } catch (Exception e) {
        StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw);
        e.printStackTrace(pw);
        LOGGER.severe(sw.toString());
    } finally {
        SecurityContextHolder.setContext(saveCtx);
    }

    return result;
}
 
@Override
public boolean isApplicable(Item item) {
    return item instanceof Job && nonNull(SCMTriggerItem.SCMTriggerItems.asSCMTriggerItem(item))
            && item instanceof ParameterizedJobMixIn.ParameterizedJob;
}