本文整理汇总了Java中hudson.model.Cause类的典型用法代码示例。如果您正苦于以下问题:Java Cause类的具体用法?Java Cause怎么用?Java Cause使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Cause类属于hudson.model包,在下文中一共展示了Cause类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getCauseEnvVars
import hudson.model.Cause; //导入依赖的package包/类
/**
* Retrieves variables describing the Run cause.
* @param run Run
* @return Set of environment variables, which depends on the cause type.
*/
@Nonnull
public static Map<String, String> getCauseEnvVars(@Nonnull Run<?, ?> run) {
CauseAction causeAction = run.getAction(CauseAction.class);
Map<String, String> env = new HashMap<>();
List<String> directCauseNames = new ArrayList<>();
Set<String> rootCauseNames = new LinkedHashSet<>();
if (causeAction != null) {
List<Cause> buildCauses = causeAction.getCauses();
for (Cause cause : buildCauses) {
directCauseNames.add(CauseHelper.getTriggerName(cause));
CauseHelper.insertRootCauseNames(rootCauseNames, cause, 0);
}
} else {
directCauseNames.add("UNKNOWN");
rootCauseNames.add("UNKNOWN");
}
env.putAll(CauseHelper.buildCauseEnvironmentVariables(ENV_CAUSE, directCauseNames));
env.putAll(CauseHelper.buildCauseEnvironmentVariables(ENV_ROOT_CAUSE, rootCauseNames));
return env;
}
示例2: insertRootCauseNames
import hudson.model.Cause; //导入依赖的package包/类
/**
* Inserts root cause names to the specified target container.
* @param causeNamesTarget Target set. May receive null items
* @param cause Cause to be added. For {@code Cause.UstreamCause} there will be in-depth search
* @param depth Current search depth. {@link #MAX_UPSTREAM_DEPTH} is a limit
*/
static void insertRootCauseNames(@Nonnull Set<String> causeNamesTarget, @CheckForNull Cause cause, int depth) {
if (cause instanceof Cause.UpstreamCause) {
if (depth == MAX_UPSTREAM_DEPTH) {
causeNamesTarget.add("DEEPLYNESTEDCAUSES");
} else {
Cause.UpstreamCause c = (Cause.UpstreamCause) cause;
List<Cause> upstreamCauses = c.getUpstreamCauses();
for (Cause upstreamCause : upstreamCauses)
insertRootCauseNames(causeNamesTarget, upstreamCause, depth + 1);
}
} else {
//TODO: Accordig to the current design this list may receive null for unknown trigger. Bug?
// Should actually return UNKNOWN
causeNamesTarget.add(getTriggerName(cause));
}
}
示例3: downstreamJobTriggerByRestrictedUser
import hudson.model.Cause; //导入依赖的package包/类
@Test
public void downstreamJobTriggerByRestrictedUser() throws Exception {
String allowedUsername = "foo";
UserSelector selector = new UserSelector(allowedUsername);
JobRestriction restriction = new StartedByUserRestriction(singletonList(selector), false, false, false);
setUpDiskPoolRestriction(restriction);
authenticate(allowedUsername);
WorkflowRun upstreamRun = createWorkflowJobAndRun();
j.assertBuildStatusSuccess(upstreamRun);
j.assertLogContains(format("Selected Disk ID '%s' from the Disk Pool ID '%s'", DISK_ID_ONE, DISK_POOL_ID), upstreamRun);
String notAllowedUsername = "bar";
authenticate(notAllowedUsername);
WorkflowJob downstreamJob = j.jenkins.createProject(WorkflowJob.class, randomAlphanumeric(7));
downstreamJob.setDefinition(new CpsFlowDefinition(format("" +
"def run = selectRun '%s' \n" +
"exwsAllocate selectedRun: run", upstreamRun.getParent().getFullName())));
WorkflowRun downstreamRun = downstreamJob.scheduleBuild2(0, new CauseAction(new Cause.UserIdCause())).get();
j.assertBuildStatus(Result.FAILURE, downstreamRun);
j.assertLogContains(format("Disk Pool identified by '%s' is not accessible due to the applied Disk Pool restriction: Started By User", DISK_POOL_ID), downstreamRun);
}
示例4: testVariableExpression
import hudson.model.Cause; //导入依赖的package包/类
/**
* Also accepts variable expression.
*/
@Test
public void testVariableExpression() throws Exception {
FreeStyleProject jobToSelect = j.createFreeStyleProject();
Run runToSelect = j.assertBuildStatusSuccess(jobToSelect.scheduleBuild2(0));
FreeStyleProject selecter = j.createFreeStyleProject();
RunSelector selector = new ParameterizedRunSelector("${SELECTOR}");
Run run = j.assertBuildStatusSuccess(selecter.scheduleBuild2(
0,
(Cause) null,
new ParametersAction(new StringParameterValue(
"SELECTOR",
"<StatusRunSelector><buildStatus>STABLE</buildStatus></StatusRunSelector>"
))
));
Run selectedRun = selector.select(jobToSelect, new RunSelectorContext(j.jenkins, run, TaskListener.NULL));
assertThat(selectedRun, is(runToSelect));
}
示例5: perform
import hudson.model.Cause; //导入依赖的package包/类
@Override
public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener)
throws InterruptedException, IOException {
for (Cause.UpstreamCause c: Util.filter(build.getCauses(), Cause.UpstreamCause.class)) {
Job<?,?> upstreamProject = Jenkins.getInstance().getItemByFullName(c.getUpstreamProject(), Job.class);
if (upstreamProject == null) {
listener.getLogger().println(String.format("Not Found: %s", c.getUpstreamProject()));
continue;
}
Run<?,?> upstreamBuild = upstreamProject.getBuildByNumber(c.getUpstreamBuild());
if (upstreamBuild == null) {
listener.getLogger().println(String.format("Not Found: %s - %d", upstreamProject.getFullName(), c.getUpstreamBuild()));
continue;
}
listener.getLogger().println(String.format("Removed: %s - %s", upstreamProject.getFullName(), upstreamBuild.getFullDisplayName()));
upstreamBuild.delete();
}
return true;
}
示例6: cancelQueuedBuild
import hudson.model.Cause; //导入依赖的package包/类
@SuppressFBWarnings("SE_BAD_FIELD")
public static boolean cancelQueuedBuild(WorkflowJob job, Build build) {
String buildUid = build.getMetadata().getUid();
final Queue buildQueue = Jenkins.getActiveInstance().getQueue();
for (final Queue.Item item : buildQueue.getItems()) {
for (Cause cause : item.getCauses()) {
if (cause instanceof BuildCause && ((BuildCause) cause).getUid().equals(buildUid)) {
return ACL.impersonate(ACL.SYSTEM, new NotReallyRoleSensitiveCallable<Boolean, RuntimeException>() {
@Override
public Boolean call() throws RuntimeException {
buildQueue.cancel(item);
return true;
}
});
}
}
}
return cancelNotYetStartedBuild(job, build);
}
示例7: started
import hudson.model.Cause; //导入依赖的package包/类
public void started(AbstractBuild build) {
CauseAction causeAction = build.getAction(CauseAction.class);
if (causeAction != null) {
Cause scmCause = causeAction.findCause(SCMTrigger.SCMTriggerCause.class);
if (scmCause == null) {
MessageBuilder message = new MessageBuilder(notifier, build);
message.append(causeAction.getShortDescription());
notifyStart(build, message.appendOpenLink().toString());
// Cause was found, exit early to prevent double-message
return;
}
}
String changes = getChanges(build, notifier.includeCustomMessage());
if (changes != null) {
notifyStart(build, changes);
} else {
notifyStart(build, getBuildStatusMessage(build, false, false,notifier.includeCustomMessage()));
}
}
示例8: getUpstreamCause
import hudson.model.Cause; //导入依赖的package包/类
private static Cause.UpstreamCause getUpstreamCause(Run run)
{
if (run == null)
{
return null;
}
List<Cause> causes = run.getCauses();
for (Cause cause : causes)
{
if (cause instanceof Cause.UpstreamCause)
{
return (Cause.UpstreamCause)cause;
}
}
return null;
}
示例9: doParamsSubmit
import hudson.model.Cause; //导入依赖的package包/类
public void doParamsSubmit(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException {
List<BuildTargetParameter> buildTargetParams;
TargetParameterBuildAction paramAction;
JSONObject jsonObject;
TargetBuildParameterUtil buildParamUtil = new TargetBuildParameterUtil();
jsonObject = req.getSubmittedForm();
buildTargetParams = buildParamUtil.parse(jsonObject);
if (buildTargetParams == null) {
rsp.sendRedirect(400, "Invalid Parameters - All Fields must be filed");
return;
} else {
paramAction = new TargetParameterBuildAction();
paramAction.setBaseBranch(jsonObject.getString("baseBranch"));
paramAction.setParameters(buildTargetParams);
Hudson.getInstance().getQueue().schedule2(project, 0, paramAction, new CauseAction(new Cause.UserIdCause()));
}
rsp.sendRedirect("../");
}
示例10: started
import hudson.model.Cause; //导入依赖的package包/类
public void started(AbstractBuild build) {
//AbstractProject<?, ?> project = build.getProject();
CauseAction causeAction = build.getAction(CauseAction.class);
if (causeAction != null) {
Cause scmCause = causeAction.findCause(SCMTrigger.SCMTriggerCause.class);
if (scmCause == null) {
MessageBuilder message = new MessageBuilder(notifier, build);
message.append(causeAction.getShortDescription());
notifyStart(build, message.appendOpenLink().toString());
// Cause was found, exit early to prevent double-message
return;
}
}
String changes = getChanges(build, notifier.includeCustomAttachmentMessage());
if (changes != null) {
notifyStart(build, changes);
} else {
notifyStart(build, getBuildStatusMessage(build, false, notifier.includeCustomAttachmentMessage()));
}
}
示例11: isUnblocked
import hudson.model.Cause; //导入依赖的package包/类
@Override
public boolean isUnblocked(Queue.Item item) {
final List<Cause> causes = item.getCauses();
for (Cause cause : causes) {
if (cause instanceof GitHubPRCause) {
final GitHubPRCause gitHubPRCause = (GitHubPRCause) cause;
final Set<String> causeLabels = gitHubPRCause.getLabels();
if (getLabel() != null) {
if (causeLabels.containsAll(label.getLabelsSet())) {
if (item.task instanceof Job<?, ?>) {
final Job<?, ?> job = (Job<?, ?>) item.task;
LOGGER.debug("Unblocking job item {} with matched labels {}",
job.getFullName(), label.getLabelsSet());
}
return true;
}
}
}
}
return false;
}
示例12: cancelQueuedBuildByBranchName
import hudson.model.Cause; //导入依赖的package包/类
/**
* Cancel previous builds for specified PR id.
*/
private static boolean cancelQueuedBuildByBranchName(final String branch) {
Queue queue = getJenkinsInstance().getQueue();
for (Queue.Item item : queue.getApproximateItemsQuickly()) {
Optional<Cause> cause = from(item.getAllActions())
.filter(instanceOf(CauseAction.class))
.transformAndConcat(new CausesFromAction())
.filter(instanceOf(GitHubBranchCause.class))
.firstMatch(new CauseHasBranch(branch));
if (cause.isPresent()) {
queue.cancel(item);
return true;
}
}
return false;
}
示例13: testSimpleWithDefaultParameter
import hudson.model.Cause; //导入依赖的package包/类
@Test
public void testSimpleWithDefaultParameter() throws Exception {
writeResourceToFile("param.yaml");
assertEquals(0, underTest.getItems().size());
YamlBuild build = underTest.scheduleBuild2(0,
new Cause.LegacyCodeCause()).get();
dumpLog(build);
assertEquals(Result.SUCCESS, build.getResult());
assertThat(CharStreams.toString(new InputStreamReader(
build.getLogInputStream())),
// Check that we wrote the default value.
containsString("bar"));
}
示例14: testSimpleWithParameter
import hudson.model.Cause; //导入依赖的package包/类
@Test
public void testSimpleWithParameter() throws Exception {
writeResourceToFile("param.yaml");
assertEquals(0, underTest.getItems().size());
ParametersAction parameters = new ParametersAction(
new StringParameterValue("foo", "baz"));
YamlBuild build = underTest.scheduleBuild2(0,
new Cause.LegacyCodeCause(), parameters).get();
dumpLog(build);
assertEquals(Result.SUCCESS, build.getResult());
assertThat(CharStreams.toString(new InputStreamReader(
build.getLogInputStream())),
// Check that we wrote the passed in parameter instead
// of the default value.
containsString("baz"));
}
示例15: doRun
import hudson.model.Cause; //导入依赖的package包/类
/** {@inheritDoc} */
@Override
protected Result doRun(BuildListener listener)
throws IOException, InterruptedException {
// Attach an SCMRevisionAction with our revision
{
final SCMHead head = getParent().getBranch().getHead();
final SCMSource source = getParent().getSource();
final SCMRevision revision = source.fetch(head, listener);
TestBuild.this.addAction(new SCMRevisionAction(checkNotNull(revision)));
}
try {
project.innerItem.scheduleBuild2(0,
new Cause.UpstreamCause(TestBuild.this)).get();
} catch (ExecutionException e) {
return Result.FAILURE;
}
return Result.SUCCESS;
}