public void testGetProjectActionHavingLastBuildGivesStarWarsAction() { AbstractProject mockProject = mock(AbstractProject.class); Build mockBuild = mock(Build.class); Quote expectedQuote = generateQuote(StarWarsResult.SUCCESS); when(mockProject.getLastBuild()).thenReturn(mockBuild); when(mockBuild.getResult()).thenReturn(Result.SUCCESS); when(mockQuotesGenerator.generate(StarWarsResult.SUCCESS)).thenReturn(expectedQuote); Action action = recorder.getProjectAction(mockProject); assertTrue(action instanceof StarWarsAction); assertEquals(StarWarsResult.SUCCESS, ((StarWarsAction) action).getResult()); assertNotNull(((StarWarsAction) action).getQuote()); }
@Nonnull @Override public Collection<String> getDockerImagesUsedByJob(@Nonnull Job<?,?> job) { if (job instanceof Project) { Project<? extends Project, ? extends Build> project = (Project<?,? extends Build>)job; Set<String> images = new HashSet<String>(); // check DockerHub build step for matching image ID for (Builder b : project.getBuilders()) { if (b instanceof DockerPullImageBuilder) { images.add(((DockerPullImageBuilder)b).getImage()); } } return images; } else { return Collections.emptySet(); } }
@Override public Object getDynamic(final String token, final StaplerRequest req, final StaplerResponse rsp) { try { final Build item = getRun(Combination.fromString(token)); if (item != null) { if (item.getNumber() == this.getNumber()) { return item; } else { // redirect the user to the correct URL String url = Functions.joinPath(item.getUrl(), req.getRestOfPath()); final String qs = req.getQueryString(); if (qs != null) { url += '?' + qs; } throw HttpResponses.redirectViaContextPath(url); } } } catch (final IllegalArgumentException e) { // failed to parse the token as Combination. Must be something else } return super.getDynamic(token, req, rsp); }
protected static void assertBuildLogContains(String msg, Build<?,?> build, String str) throws IOException { assertNotNull("Build shouldn't be null", build); assertNotNull("Pattern shouldn't be null", str); String log = FileUtils.readFileToString(build.getLogFile()); System.out.println(log); assertNotNull("Build log shouldn't be null", log); assertTrue(msg, log.contains(str)); }
public Build getRun(final Combination combination) { for (final DynamicSubProject subProject : getAllSubProjects()) { if (subProject.getCombination().equals(combination)) { return getRunForConfiguration(subProject); } } return null; }
public String getNearestRunUrl() { final Build r = getRun(); if (r == null) { return null; } if (this.dynamicBuild.getNumber() == r.getNumber()) { return getShortUrl() + "/console"; } return Stapler.getCurrentRequest().getContextPath() + '/' + r.getUrl(); }
public String getTooltip() { final Build r = getRun(); if (r != null) { return r.getIconColor().getDescription(); } final Queue.Item item = Jenkins.getInstance().getQueue().getItem(this.dynamicBuild.getParent().getItem(this.combination)); if (item != null) { return item.getWhy(); } return null; // fall back }
@Override public boolean perform(Build<?, ?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException { initPython(); if (pexec.isImplemented(7)) { return pexec.execPythonBool("perform", build, launcher, listener); } else { return super.perform(build, launcher, listener); } }
protected static void assertDeploySucceeded(Build<?,?> build) throws IOException { assertBuildLogContains("Deploy wasn't successful.", build, "Application deployed to http://"); }
public Build getRun() { return this.dynamicBuild.getRun(this.combination); }
public boolean superPerform(Build<?, ?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException { return super.perform(build, launcher, listener); }
public static boolean inheritanceLookupRequired(InheritanceProject root, boolean forcedInherit) { //In a cyclic dependency, any form of inheritance would be ill-advised try { if (root.hasCyclicDependency()) { return false; } } catch (NullPointerException ex) { //The project might not be loaded completely yet; this will cause //an NPE which means no inheritance should be queried return false; } /* Otherwise, an exploration is only required when one of the following * holds: * 1.) The user wants to force inheritance * 2.) The project is transient and has no real own configuration * 3.) The project is called in the context of a build * 4.) The queue queries properties of the project */ //Check forced inheritance or transience if (forcedInherit || root.getIsTransient()) { return true; } //Checking the Stapler Request, because it is fast StaplerRequest req = Stapler.getCurrentRequest(); if (req != null) { String uri = req.getRequestURI(); //Check if we request the build page if (uri.endsWith("/build")) { return true; } //Check if we were requested by page for a run if (runUriRegExp.matcher(uri).matches()) { return true; } } //Check via expensive stack reflection if (Reflection.calledFromClass( Build.class, BuildCommand.class, Queue.class, BuildTrigger.class, Trigger.class, BuildStep.class ) || Reflection.calledFromMethod( InheritanceProject.class, "doBuild", "scheduleBuild2", "doBuildWithParameters" ) ) { return true; } //In all other cases, we don't require (or want) inheritance return false; }