本文整理汇总了Java中hudson.model.CauseAction类的典型用法代码示例。如果您正苦于以下问题:Java CauseAction类的具体用法?Java CauseAction怎么用?Java CauseAction使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CauseAction类属于hudson.model包,在下文中一共展示了CauseAction类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getCauseEnvVars
import hudson.model.CauseAction; //导入依赖的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: downstreamJobTriggerByRestrictedUser
import hudson.model.CauseAction; //导入依赖的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);
}
示例3: started
import hudson.model.CauseAction; //导入依赖的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()));
}
}
示例4: doParamsSubmit
import hudson.model.CauseAction; //导入依赖的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("../");
}
示例5: started
import hudson.model.CauseAction; //导入依赖的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()));
}
}
示例6: cancelQueuedBuildByBranchName
import hudson.model.CauseAction; //导入依赖的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;
}
示例7: should_get_cause_from_dbObject
import hudson.model.CauseAction; //导入依赖的package包/类
@Test
public void should_get_cause_from_dbObject() throws Exception {
BasicDBObject cause1DbObject = new BasicDBObject("cause1", "cause1");
DBObject causes = new BasicDBObjectBuilder().add("causes", Arrays.asList(cause1DbObject)).get();
Mapper mapper = Mockito.mock(Mapper.class);
Cause cause1 = new NullBuildCause();
when(mapper.fromDBObject(null, cause1DbObject, null)).thenReturn(cause1);
CauseActionConverter converter = new CauseActionConverter();
converter.setMapper(mapper);
CauseAction action = converter.decode(CauseAction.class, causes, Mockito.mock(MappedField.class));
Assert.assertEquals(1, action.getCauses().size());
Assert.assertEquals(cause1, action.getCauses().get(0));
}
示例8: should_convert_cause_action_to_old_format
import hudson.model.CauseAction; //导入依赖的package包/类
@Test
public void should_convert_cause_action_to_old_format() throws Exception {
Cause cause1 = new NullBuildCause();
Mapper mapper = Mockito.mock(Mapper.class);
when(mapper.toDBObject(cause1)).thenReturn(new BasicDBObject("cause1", "cause1"));
CauseAction causeAction = new CauseAction(cause1);
CauseActionConverter converter = new CauseActionConverter();
converter.setMapper(mapper);
DBObject dbObject = (DBObject) converter.encode(causeAction, null);
Assert.assertEquals(dbObject.get("className"), CauseAction.class.getName());
Assert.assertNotNull(dbObject.get("causes"));
List dbCauses = ((List) dbObject.get("causes"));
Assert.assertEquals(1, dbCauses.size());
Assert.assertEquals("cause1", ((BasicDBObject) dbCauses.get(0)).get("cause1"));
}
示例9: triggerRebuild
import hudson.model.CauseAction; //导入依赖的package包/类
@Override
public void triggerRebuild(String projectName, String buildId) {
AbstractProject project = ProjectUtil.getProject(projectName, Jenkins.getInstance());
if (!project.hasPermission(Item.BUILD)) {
throw new BadCredentialsException("Not authorized to trigger build");
}
AbstractBuild build = project.getBuildByNumber(Integer.parseInt(buildId));
@SuppressWarnings("unchecked")
List<Cause> prevCauses = build.getCauses();
List<Cause> newCauses = new ArrayList<>();
for (Cause cause : prevCauses) {
if (!(cause instanceof Cause.UserIdCause)) {
newCauses.add(cause);
}
}
newCauses.add(new Cause.UserIdCause());
CauseAction causeAction = new CauseAction(newCauses);
project.scheduleBuild2(project.getQuietPeriod(),null, causeAction, build.getAction(ParametersAction.class));
}
示例10: getUpstreamBuild
import hudson.model.CauseAction; //导入依赖的package包/类
@CheckForNull
public static AbstractBuild getUpstreamBuild(AbstractBuild build) {
List<CauseAction> actions = build.getActions(CauseAction.class);
for (CauseAction action : actions) {
List<Cause.UpstreamCause> causes = Util.filter(action.getCauses(), Cause.UpstreamCause.class);
if (!causes.isEmpty()) {
Cause.UpstreamCause upstreamCause = causes.get(0);
AbstractProject upstreamProject = JenkinsUtil.getInstance().getItemByFullName(
upstreamCause.getUpstreamProject(), AbstractProject.class);
//Due to https://issues.jenkins-ci.org/browse/JENKINS-14030 when a project has been renamed triggers
// are not updated correctly
if (upstreamProject == null) {
return null;
}
return upstreamProject.getBuildByNumber(upstreamCause.getUpstreamBuild());
}
}
return null;
}
示例11: testGetTriggeredByMultipleSCMChange
import hudson.model.CauseAction; //导入依赖的package包/类
@Test
@Issue("JENKINS-22611")
public void testGetTriggeredByMultipleSCMChange() throws Exception {
FreeStyleProject project = jenkins.createFreeStyleProject("build");
FakeRepositoryBrowserSCM scm = new FakeRepositoryBrowserSCM();
scm.addChange().withAuthor("test-user").withMsg("Fixed bug");
project.setScm(scm);
jenkins.setQuietPeriod(0);
CauseAction action = new CauseAction(new SCMTrigger.SCMTriggerCause(""));
action.getCauses().add(new SCMTrigger.SCMTriggerCause(""));
action.getCauses().add(new SCMTrigger.SCMTriggerCause(""));
action.getCauses().add(new SCMTrigger.SCMTriggerCause(""));
project.scheduleBuild(0, null, action);
jenkins.waitUntilNoActivity();
List<TriggerCause> triggeredBy = TriggerCause.getTriggeredBy(project, project.getLastBuild());
assertEquals(1, triggeredBy.size());
assertEquals(TriggerCause.TYPE_SCM, triggeredBy.iterator().next().getType());
}
示例12: createWorkflowJobAndRun
import hudson.model.CauseAction; //导入依赖的package包/类
private static WorkflowRun createWorkflowJobAndRun(String jobName) throws Exception {
WorkflowJob job = j.jenkins.createProject(WorkflowJob.class, jobName);
job.setDefinition(new CpsFlowDefinition(format("exwsAllocate diskPoolId: '%s'", DISK_POOL_ID)));
Future<WorkflowRun> runFuture = job.scheduleBuild2(0, new CauseAction(new Cause.UserIdCause()));
assertThat(runFuture, notNullValue());
return runFuture.get();
}
示例13: initialize
import hudson.model.CauseAction; //导入依赖的package包/类
static synchronized void initialize() {
if (buildToParametersMap == null) {
buildToParametersMap = new ConcurrentHashMap<String, ParametersAction>();
}
if (buildToCauseMap == null) {
buildToCauseMap = new ConcurrentHashMap<String, CauseAction>();
}
}
示例14: isOpenShiftBuildCause
import hudson.model.CauseAction; //导入依赖的package包/类
private static boolean isOpenShiftBuildCause(List<Action> actions) {
for (Action action : actions) {
if (action instanceof CauseAction) {
CauseAction causeAction = (CauseAction) action;
for (Cause cause : causeAction.getCauses()) {
if (cause instanceof BuildCause) {
return true;
}
}
}
}
return false;
}
示例15: dumpCause
import hudson.model.CauseAction; //导入依赖的package包/类
private static CauseAction dumpCause(List<Action> actions) {
for (Action action : actions) {
if (action instanceof CauseAction) {
CauseAction causeAction = (CauseAction) action;
if (LOGGER.isLoggable(Level.FINE))
for (Cause cause : causeAction.getCauses()) {
LOGGER.fine("cause: " + cause.getShortDescription());
}
return causeAction;
}
}
return null;
}