本文整理汇总了Java中hudson.model.Cause.UpstreamCause方法的典型用法代码示例。如果您正苦于以下问题:Java Cause.UpstreamCause方法的具体用法?Java Cause.UpstreamCause怎么用?Java Cause.UpstreamCause使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类hudson.model.Cause
的用法示例。
在下文中一共展示了Cause.UpstreamCause方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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));
}
}
示例2: 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;
}
示例3: 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;
}
示例4: isQueued
import hudson.model.Cause; //导入方法依赖的package包/类
public static boolean isQueued(AbstractProject project, AbstractBuild firstBuild) {
if (!project.isInQueue()) {
return false;
} else if (firstBuild == null) {
return true;
}
List<Cause.UpstreamCause> causes = Util.filter(project.getQueueItem().getCauses(),
Cause.UpstreamCause.class);
@SuppressWarnings("unchecked")
List<AbstractProject<?,?>> upstreamProjects = project.getUpstreamProjects();
for (AbstractProject<?, ?> upstreamProject : upstreamProjects) {
AbstractBuild upstreamBuild = BuildUtil.match(upstreamProject.getBuilds(), firstBuild);
if (upstreamBuild != null) {
for (Cause.UpstreamCause upstreamCause : causes) {
if (upstreamBuild.getNumber() == upstreamCause.getUpstreamBuild()
&& upstreamProject.getRelativeNameFrom(JenkinsUtil.getInstance()).equals(
upstreamCause.getUpstreamProject())) {
return true;
}
}
}
}
return false;
}
示例5: getUpstreamBuild
import hudson.model.Cause; //导入方法依赖的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;
}
示例6: getUpstreamBuild
import hudson.model.Cause; //导入方法依赖的package包/类
/**
* Get the root upstream build which caused this build. Useful in build pipelines to
* be able to extract the changes which started the pipeline in later stages of
* the pipeline
*
* @return
*/
public static AbstractBuild getUpstreamBuild(AbstractBuild<?, ?> build)
{
logger.log(Level.FINE, "Find build upstream of " + build.getId());
Cause.UpstreamCause cause = getUpstreamCause(build);
if (cause == null)
{
logger.log(Level.FINE, "No upstream cause, so must be upstream build: " + build.getId());
return build;
}
logger.log(Level.FINE, "Found upstream cause: " + cause.toString() + "(" + cause.getShortDescription() + ")");
AbstractProject project = (AbstractProject) Jenkins.getInstance().getItem(cause.getUpstreamProject(), build.getProject());
if (project == null)
{
logger.log(Level.WARNING, "Found an UpstreamCause (" + cause.toString()
+ "), but the upstream project (" + cause.getUpstreamProject() + ") does not appear to be valid!");
logger.log(Level.WARNING, "Using build [" + build.getId() + "] as the upstream build - this is likely incorrect.");
return build;
}
AbstractBuild upstreamBuild = project.getBuildByNumber(cause.getUpstreamBuild());
if (upstreamBuild == null)
{
logger.log(Level.WARNING, "Found an UpstreamCause (" + cause.toString()
+ "), and an upstream project (" + project.getName() + "), but the build is invalid!" + cause.getUpstreamBuild());
logger.log(Level.WARNING, "Using build [" + build.getId() + "] as the upstream build - this is likely incorrect.");
return build;
}
return getUpstreamBuild(upstreamBuild);
}
示例7: getUpstreamRun
import hudson.model.Cause; //导入方法依赖的package包/类
@VisibleForTesting
static Run<?, ?> getUpstreamRun(AbstractBuild build) {
CauseAction action = build.getAction(hudson.model.CauseAction.class);
if (action != null) {
Cause.UpstreamCause upstreamCause = action.findCause(hudson.model.Cause.UpstreamCause.class);
if (upstreamCause != null) {
return upstreamCause.getUpstreamRun();
}
}
return null;
}
示例8: getParentBuild
import hudson.model.Cause; //导入方法依赖的package包/类
/**
* Potentially recursively walk the upstream builds until we find one that
* originates from {@code parentProject}.
*
* @param parentProject The containing project from which we inherit our
* actual {@link SCM}
* @param build The build we are tracing back to its possible origin at
* {@code parentProject}.
* @return The build of {@code parentProject} that (possibly transititvely)
* caused {@code build}.
*/
private AbstractBuild getParentBuild(T parentProject, AbstractBuild build) {
for (final CauseAction action : build.getActions(CauseAction.class)) {
for (final Cause cause : action.getCauses()) {
if (!(cause instanceof Cause.UpstreamCause)) {
continue;
}
final Cause.UpstreamCause upstreamCause = (Cause.UpstreamCause) cause;
// If our parent project caused this build, then return its build that
// triggered this.
final String upstreamProjectName = parentProject.getFullName();
final AbstractProject causeProject =
((AbstractProject) checkNotNull(Jenkins.getInstance())
.getItemByFullName(upstreamCause.getUpstreamProject()));
if (causeProject == null) {
throw new IllegalStateException(
"Unable to lookup upstream cause project");
}
AbstractBuild causeBuild = causeProject.getBuildByNumber(
upstreamCause.getUpstreamBuild());
if (upstreamCause.getUpstreamProject().equals(upstreamProjectName)) {
return causeBuild;
}
// Otherwise, see if the build that triggered our build was triggered by
// our parent project (transitively)
causeBuild = getParentBuild(parentProject, causeBuild);
if (causeBuild != null) {
return causeBuild;
}
}
}
throw new IllegalStateException(Messages.DelegateSCM_NoParentBuild());
}
示例9: isSkip
import hudson.model.Cause; //导入方法依赖的package包/类
/**
* 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;
}
示例10: resolveCause
import hudson.model.Cause; //导入方法依赖的package包/类
@Override
public TriggerCause resolveCause(Cause cause) {
if (cause instanceof Cause.UserIdCause) {
return new TriggerCause(TriggerCause.TYPE_MANUAL, "user "
+ getDisplayName(((Cause.UserIdCause) cause).getUserName()));
} else if (cause instanceof Cause.RemoteCause) {
return new TriggerCause(TriggerCause.TYPE_REMOTE, "remote trigger");
} else if (cause instanceof Cause.UpstreamCause) {
Cause.UpstreamCause upstreamCause = (Cause.UpstreamCause) cause;
AbstractProject upstreamProject = JenkinsUtil.getInstance().getItem(upstreamCause.getUpstreamProject(),
JenkinsUtil.getInstance(), AbstractProject.class);
StringBuilder causeString = new StringBuilder("upstream project");
if (upstreamProject != null) {
causeString.append(" ").append(upstreamProject.getDisplayName());
AbstractBuild upstreamBuild = upstreamProject.getBuildByNumber(upstreamCause.getUpstreamBuild());
if (upstreamBuild != null) {
causeString.append(" build ").append(upstreamBuild.getDisplayName());
}
}
return new TriggerCause(TriggerCause.TYPE_UPSTREAM, causeString.toString());
} else if (cause instanceof Cause.UpstreamCause.DeeplyNestedUpstreamCause) {
return new TriggerCause(TriggerCause.TYPE_UPSTREAM, "upstream");
} else if (cause instanceof SCMTrigger.SCMTriggerCause) {
return new TriggerCause(TriggerCause.TYPE_SCM, "SCM");
} else if (cause instanceof TimerTrigger.TimerTriggerCause) {
return new TriggerCause(TriggerCause.TYPE_TIMER, "timer");
} else {
return null;
}
}
示例11: testGetUpstreamBuildProjectRenamed
import hudson.model.Cause; //导入方法依赖的package包/类
@Test
public void testGetUpstreamBuildProjectRenamed() {
AbstractBuild build = mock(AbstractBuild.class);
List<CauseAction> causeActions = new ArrayList<>();
Cause.UpstreamCause cause = mock(Cause.UpstreamCause.class);
when(cause.getUpstreamProject()).thenReturn("thisprojectdontexists");
causeActions.add(new CauseAction(cause));
when(build.getActions(CauseAction.class)).thenReturn(causeActions);
assertNull(BuildUtil.getUpstreamBuild(build));
}
示例12: verify_downstream_simple_pipeline_trigger
import hudson.model.Cause; //导入方法依赖的package包/类
/**
* The maven-war-app has a dependency on the maven-jar-app
*/
@Test
public void verify_downstream_simple_pipeline_trigger() throws Exception {
System.out.println("gitRepoRule: " + gitRepoRule);
loadMavenJarProjectInGitRepo(this.gitRepoRule);
System.out.println("downstreamArtifactRepoRule: " + downstreamArtifactRepoRule);
loadMavenWarProjectInGitRepo(this.downstreamArtifactRepoRule);
String mavenJarPipelineScript = "node('master') {\n" +
" git($/" + gitRepoRule.toString() + "/$)\n" +
" withMaven() {\n" +
" sh 'mvn install'\n" +
" }\n" +
"}";
String mavenWarPipelineScript = "node('master') {\n" +
" git($/" + downstreamArtifactRepoRule.toString() + "/$)\n" +
" withMaven() {\n" +
" sh 'mvn install'\n" +
" }\n" +
"}";
WorkflowJob mavenJarPipeline = jenkinsRule.createProject(WorkflowJob.class, "build-maven-jar");
mavenJarPipeline.setDefinition(new CpsFlowDefinition(mavenJarPipelineScript, true));
mavenJarPipeline.addTrigger(new WorkflowJobDependencyTrigger());
WorkflowRun mavenJarPipelineFirstRun = jenkinsRule.assertBuildStatus(Result.SUCCESS, mavenJarPipeline.scheduleBuild2(0));
// TODO check in DB that the generated artifact is recorded
WorkflowJob mavenWarPipeline = jenkinsRule.createProject(WorkflowJob.class, "build-maven-war");
mavenWarPipeline.setDefinition(new CpsFlowDefinition(mavenWarPipelineScript, true));
mavenWarPipeline.addTrigger(new WorkflowJobDependencyTrigger());
WorkflowRun mavenWarPipelineFirstRun = jenkinsRule.assertBuildStatus(Result.SUCCESS, mavenWarPipeline.scheduleBuild2(0));
// TODO check in DB that the dependency on the war project is recorded
System.out.println("mavenWarPipelineFirstRun: " + mavenWarPipelineFirstRun);
WorkflowRun mavenJarPipelineSecondRun = jenkinsRule.assertBuildStatus(Result.SUCCESS, mavenJarPipeline.scheduleBuild2(0));
jenkinsRule.waitUntilNoActivity();
WorkflowRun mavenWarPipelineLastRun = mavenWarPipeline.getLastBuild();
System.out.println("mavenWarPipelineLastBuild: " + mavenWarPipelineLastRun + " caused by " + mavenWarPipelineLastRun.getCauses());
assertThat(mavenWarPipelineLastRun.getNumber(), is(mavenWarPipelineFirstRun.getNumber() + 1));
Cause.UpstreamCause upstreamCause = mavenWarPipelineLastRun.getCause(Cause.UpstreamCause.class);
assertThat(upstreamCause, notNullValue());
}
示例13: verify_downstream_multi_branch_pipeline_trigger
import hudson.model.Cause; //导入方法依赖的package包/类
/**
* The maven-war-app has a dependency on the maven-jar-app
*/
@Test
public void verify_downstream_multi_branch_pipeline_trigger() throws Exception {
System.out.println("gitRepoRule: " + gitRepoRule);
loadMavenJarProjectInGitRepo(this.gitRepoRule);
System.out.println("downstreamArtifactRepoRule: " + downstreamArtifactRepoRule);
loadMavenWarProjectInGitRepo(this.downstreamArtifactRepoRule);
String script = "node('master') {\n" +
" checkout scm\n" +
" withMaven() {\n" +
" sh 'mvn install'\n" +
" }\n" +
"}";
gitRepoRule.write("Jenkinsfile", script);
gitRepoRule.git("add", "Jenkinsfile");
gitRepoRule.git("commit", "--message=jenkinsfile");
downstreamArtifactRepoRule.write("Jenkinsfile", script);
downstreamArtifactRepoRule.git("add", "Jenkinsfile");
downstreamArtifactRepoRule.git("commit", "--message=jenkinsfile");
// TRIGGER maven-jar#1 to record that "build-maven-jar" generates this jar and install this maven jar in the local maven repo
WorkflowMultiBranchProject mavenJarPipeline = jenkinsRule.createProject(WorkflowMultiBranchProject.class, "build-maven-jar");
mavenJarPipeline.addTrigger(new WorkflowJobDependencyTrigger());
mavenJarPipeline.getSourcesList().add(new BranchSource(new GitSCMSource(null, gitRepoRule.toString(), "", "*", "", false)));
System.out.println("trigger maven-jar#1...");
WorkflowJob mavenJarPipelineMasterPipeline = WorkflowMultibranchProjectTestsUtils.scheduleAndFindBranchProject(mavenJarPipeline, "master");
assertEquals(1, mavenJarPipeline.getItems().size());
System.out.println("wait for maven-jar#1...");
jenkinsRule.waitUntilNoActivity();
assertThat(mavenJarPipelineMasterPipeline.getLastBuild().getNumber(), is(1));
// TODO check in DB that the generated artifact is recorded
// TRIGGER maven-war#1 to record that "build-maven-war" has a dependency on "build-maven-jar"
WorkflowMultiBranchProject mavenWarPipeline = jenkinsRule.createProject(WorkflowMultiBranchProject.class, "build-maven-war");
mavenWarPipeline.addTrigger(new WorkflowJobDependencyTrigger());
mavenWarPipeline.getSourcesList().add(new BranchSource(new GitSCMSource(null, downstreamArtifactRepoRule.toString(), "", "*", "", false)));
System.out.println("trigger maven-war#1...");
WorkflowJob mavenWarPipelineMasterPipeline = WorkflowMultibranchProjectTestsUtils.scheduleAndFindBranchProject(mavenWarPipeline, "master");
assertEquals(1, mavenWarPipeline.getItems().size());
System.out.println("wait for maven-war#1...");
jenkinsRule.waitUntilNoActivity();
WorkflowRun mavenWarPipelineFirstRun = mavenWarPipelineMasterPipeline.getLastBuild();
// TODO check in DB that the dependency on the war project is recorded
// TRIGGER maven-jar#2 so that it triggers "maven-war" and creates maven-war#2
System.out.println("trigger maven-jar#2...");
Future<WorkflowRun> mavenJarPipelineMasterPipelineSecondRunFuture = mavenJarPipelineMasterPipeline.scheduleBuild2(0, new CauseAction(new Cause.RemoteCause("127.0.0.1", "junit test")));
System.out.println("wait for maven-jar#2...");
mavenJarPipelineMasterPipelineSecondRunFuture.get();
jenkinsRule.waitUntilNoActivity();
WorkflowRun mavenWarPipelineLastRun = mavenWarPipelineMasterPipeline.getLastBuild();
System.out.println("mavenWarPipelineLastBuild: " + mavenWarPipelineLastRun + " caused by " + mavenWarPipelineLastRun.getCauses());
assertThat(mavenWarPipelineLastRun.getNumber(), is(mavenWarPipelineFirstRun.getNumber() + 1));
Cause.UpstreamCause upstreamCause = mavenWarPipelineLastRun.getCause(Cause.UpstreamCause.class);
assertThat(upstreamCause, notNullValue());
}
示例14: verify_downstream_pipeline_triggered_on_parent_pom_build
import hudson.model.Cause; //导入方法依赖的package包/类
/**
* The maven-war-app has a dependency on the maven-jar-app
*/
@Test
public void verify_downstream_pipeline_triggered_on_parent_pom_build() throws Exception {
System.out.println("gitRepoRule: " + gitRepoRule);
loadMavenJarProjectInGitRepo(this.gitRepoRule);
System.out.println("downstreamArtifactRepoRule: " + downstreamArtifactRepoRule);
loadMavenWarProjectInGitRepo(this.downstreamArtifactRepoRule);
String mavenJarPipelineScript = "node('master') {\n" +
" git($/" + gitRepoRule.toString() + "/$)\n" +
" withMaven() {\n" +
" sh 'mvn install'\n" +
" }\n" +
"}";
String mavenWarPipelineScript = "node('master') {\n" +
" git($/" + downstreamArtifactRepoRule.toString() + "/$)\n" +
" withMaven() {\n" +
" sh 'mvn install'\n" +
" }\n" +
"}";
WorkflowJob mavenJarPipeline = jenkinsRule.createProject(WorkflowJob.class, "build-maven-jar");
mavenJarPipeline.setDefinition(new CpsFlowDefinition(mavenJarPipelineScript, true));
mavenJarPipeline.addTrigger(new WorkflowJobDependencyTrigger());
WorkflowRun mavenJarPipelineFirstRun = jenkinsRule.assertBuildStatus(Result.SUCCESS, mavenJarPipeline.scheduleBuild2(0));
// TODO check in DB that the generated artifact is recorded
WorkflowJob mavenWarPipeline = jenkinsRule.createProject(WorkflowJob.class, "build-maven-war");
mavenWarPipeline.setDefinition(new CpsFlowDefinition(mavenWarPipelineScript, true));
mavenWarPipeline.addTrigger(new WorkflowJobDependencyTrigger());
WorkflowRun mavenWarPipelineFirstRun = jenkinsRule.assertBuildStatus(Result.SUCCESS, mavenWarPipeline.scheduleBuild2(0));
// TODO check in DB that the dependency on the war project is recorded
System.out.println("mavenWarPipelineFirstRun: " + mavenWarPipelineFirstRun);
WorkflowRun mavenJarPipelineSecondRun = jenkinsRule.assertBuildStatus(Result.SUCCESS, mavenJarPipeline.scheduleBuild2(0));
jenkinsRule.waitUntilNoActivity();
WorkflowRun mavenWarPipelineLastRun = mavenWarPipeline.getLastBuild();
System.out.println("mavenWarPipelineLastBuild: " + mavenWarPipelineLastRun + " caused by " + mavenWarPipelineLastRun.getCauses());
assertThat(mavenWarPipelineLastRun.getNumber(), is(mavenWarPipelineFirstRun.getNumber() + 1));
Cause.UpstreamCause upstreamCause = mavenWarPipelineLastRun.getCause(Cause.UpstreamCause.class);
assertThat(upstreamCause, notNullValue());
}