use of hudson.model.Cause in project gogs-webhook-plugin by jenkinsci.
the class GogsPayloadProcessor method triggerJobs.
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;
}
use of hudson.model.Cause in project workflow-job-plugin by jenkinsci.
the class BuildTriggerTest method smokes.
@Issue("JENKINS-28113")
@Test
public void smokes() throws Exception {
BuildTrigger.DescriptorImpl d = r.jenkins.getDescriptorByType(BuildTrigger.DescriptorImpl.class);
FreeStyleProject us = r.createProject(FreeStyleProject.class, "us");
WorkflowJob ds = r.createProject(WorkflowJob.class, "ds");
ds.setDefinition(new CpsFlowDefinition("", true));
assertEquals(Collections.singletonList("ds"), d.doAutoCompleteChildProjects("d", us, r.jenkins).getValues());
FormValidation validation = d.doCheck(us, "ds");
assertEquals(validation.renderHtml(), FormValidation.Kind.OK, validation.kind);
us.getPublishersList().add(new BuildTrigger("ds", Result.SUCCESS));
r.jenkins.setQuietPeriod(0);
FreeStyleBuild us1 = r.buildAndAssertSuccess(us);
r.waitUntilNoActivity();
WorkflowRun ds1 = ds.getLastBuild();
assertNotNull("triggered", ds1);
Cause.UpstreamCause cause = ds1.getCause(Cause.UpstreamCause.class);
assertNotNull(cause);
assertEquals(us1, cause.getUpstreamRun());
}
use of hudson.model.Cause in project dependency-check-plugin by jenkinsci.
the class AbstractDependencyCheckBuilder method isSkip.
/**
* Determine if the build should be skipped or not
*/
private boolean isSkip(final Run<?, ?> build, final TaskListener listener) {
boolean skip = false;
// Determine if the OWASP_DC_SKIP environment variable is set to true
try {
skip = Boolean.parseBoolean(build.getEnvironment(listener).get("OWASP_DC_SKIP"));
} catch (Exception e) {
/* throw it away */
}
// Why was this build triggered? Get the causes and find out.
@SuppressWarnings("unchecked") final List<Cause> causes = build.getCauses();
for (Cause cause : causes) {
// Skip if the build is configured to skip on SCM change and the cause of the build was an SCM trigger
if (skipOnScmChange && cause instanceof SCMTrigger.SCMTriggerCause) {
skip = true;
}
// Skip if the build is configured to skip on Upstream change and the cause of the build was an Upstream trigger
if (skipOnUpstreamChange && cause instanceof Cause.UpstreamCause) {
skip = true;
}
}
// Log a message if being skipped
if (skip) {
listener.getLogger().println(OUT_TAG + "Skipping Dependency-Check analysis.");
}
return skip;
}
use of hudson.model.Cause in project sonar-scanner-jenkins by SonarSource.
the class TriggersConfig method isSkipSonar.
public String isSkipSonar(AbstractBuild<?, ?> build, BuildListener listener) throws IOException, InterruptedException {
Result result = build.getResult();
if (result != null && result.isWorseThan(Result.UNSTABLE)) {
// unstable means that build completed, but there were some test failures, which is not critical for analysis
return Messages.SonarPublisher_BadBuildStatus(result.toString());
}
// skip analysis by environment variable or build parameter
if (getEnvVar() != null) {
// check against build parameters
String value = build.getBuildVariableResolver().resolve(getEnvVar());
if ("true".equalsIgnoreCase(value)) {
return Messages.Skipping_Sonar_analysis();
}
// check against environment variable
EnvVars envVars = build.getEnvironment(listener);
value = new VariableResolver.ByMap<>(envVars).resolve(getEnvVar());
if ("true".equalsIgnoreCase(value)) {
return Messages.Skipping_Sonar_analysis();
}
}
List<Cause> causes = new ArrayList<>(build.getCauses());
// skip analysis, when all causes from blacklist
if (isSkipScmCause() || isSkipUpstreamCause()) {
Iterator<Cause> iter = causes.iterator();
while (iter.hasNext()) {
Cause cause = iter.next();
if ((isSkipScmCause() && SCMTrigger.SCMTriggerCause.class.isInstance(cause)) || (isSkipUpstreamCause() && Cause.UpstreamCause.class.isInstance(cause))) {
iter.remove();
}
}
}
return causes.isEmpty() ? Messages.Skipping_Sonar_analysis() : null;
}
use of hudson.model.Cause in project blueocean-plugin by jenkinsci.
the class DownstreamJobListener method onStarted.
@Override
public void onStarted(Run<?, ?> run, TaskListener listener) {
for (Cause cause : run.getCauses()) {
if (cause instanceof BuildUpstreamCause) {
BuildUpstreamCause buildUpstreamCause = (BuildUpstreamCause) cause;
Run triggerRun = buildUpstreamCause.getUpstreamRun();
if (triggerRun instanceof WorkflowRun) {
FlowExecution execution = ((WorkflowRun) triggerRun).getExecution();
FlowNode node;
if (execution == null) {
LOGGER.warning("Could not retrieve upstream FlowExecution");
continue;
}
try {
node = execution.getNode(buildUpstreamCause.getNodeId());
} catch (IOException e) {
LOGGER.warning("Could not retrieve upstream node: " + e);
continue;
}
if (node == null) {
LOGGER.warning("Could not retrieve upstream node (null)");
continue;
}
// Add an action on the triggerRun node pointing to the currently executing run
String description = run.getDescription();
if (description == null) {
description = run.getFullDisplayName();
}
Link link = LinkResolver.resolveLink(run);
if (link != null) {
try {
// Also add to the actual trigger node so we can find it later by step
node.addAction(new NodeDownstreamBuildAction(link, description));
node.save();
} catch (IOException e) {
LOGGER.severe("Could not persist node: " + e);
}
}
}
}
}
}
Aggregations