Skip to content
Permalink
Browse files

Merge pull request #5 from fbelzunc/JENKINS-35411

[JENKINS-35411] Migrate batch-task-plugin to 2.x parent pom
  • Loading branch information...
fbelzunc committed Jun 7, 2016
2 parents 25303f8 + f801d3e commit ec3d5cf5096094b647e372dfb8c020c491df4b4d
35 pom.xml
@@ -4,7 +4,7 @@
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>1.424</version>
<version>2.9</version>
</parent>

<artifactId>batch-task</artifactId>
@@ -13,6 +13,13 @@
<name>Jenkins batch task plugin</name>
<url>http://wiki.jenkins-ci.org/display/JENKINS/Batch+Task+Plugin</url>

<properties>
<jenkins.version>1.580.1</jenkins.version>
<java.level>6</java.level>
<powermock.version>1.6.1</powermock.version>
<findbugs.failOnError>false</findbugs.failOnError>
</properties>

<developers>
<developer>
<id>kohsuke</id>
@@ -24,20 +31,6 @@
</developer>
</developers>

<build>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<!-- TODO: please remove this exclude, once the parent is updated to v1.385+ -->
<excludes>
<exclude>**/BatchRunTest.*</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>

<scm>
<connection>scm:git:git://github.com/jenkinsci/${project.artifactId}-plugin.git</connection>
<developerConnection>scm:git:git@github.com:jenkinsci/${project.artifactId}-plugin.git</developerConnection>
@@ -48,21 +41,27 @@
<dependency>
<groupId>org.jenkins-ci.lib</groupId>
<artifactId>envinject-lib</artifactId>
<version>1.16</version>
<version>1.23</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>matrix-project</artifactId>
<version>1.4</version>
<scope>test</scope>
</dependency>
</dependencies>

<repositories>
<repository>
<id>repo.jenkins-ci.org</id>
<url>http://repo.jenkins-ci.org/public/</url>
<url>https://repo.jenkins-ci.org/public/</url>
</repository>
</repositories>

<pluginRepositories>
<pluginRepository>
<id>repo.jenkins-ci.org</id>
<url>http://repo.jenkins-ci.org/public/</url>
<url>https://repo.jenkins-ci.org/public/</url>
</pluginRepository>
</pluginRepositories>

@@ -22,10 +22,12 @@
import hudson.widgets.HistoryWidget.Adapter;
import hudson.security.ACL;
import jenkins.model.Jenkins;
import org.acegisecurity.Authentication;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerResponse;

import javax.annotation.Nonnull;
import javax.servlet.ServletException;
import java.io.IOException;
import java.util.Collection;
@@ -365,6 +367,13 @@ public String toString(Object item) {
return Collections.singleton(this);
}

/** {@inheritDoc} */
@Nonnull
@Override
public Authentication getDefaultAuthentication() {
return ACL.SYSTEM;
}

/**
* {@inheritDoc}
*/
@@ -1,6 +1,7 @@
<!--
Displays the execution log
-->
<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form" xmlns:i="jelly:fmt">
<l:layout title="${%title(it.displayName)}" norefresh="true">
<l:header />
@@ -1,3 +1,4 @@
<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form" xmlns:i="jelly:fmt" xmlns:local="local">
<l:layout title="${%title(it.owner.parent.displayName,it.owner.displayName)}">
<st:include page="sidepanel.jelly" it="${it.owner}" />
@@ -1,6 +1,7 @@
<!--
Delete this task.
-->
<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form" xmlns:i="jelly:fmt">
<l:layout>
<st:include page="sidepanel.jelly" />
@@ -1,3 +1,4 @@
<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form" xmlns:i="jelly:fmt" xmlns:p="/lib/hudson/project">
<l:layout title="${it.displayName}">
<st:include page="sidepanel.jelly" />
@@ -1,3 +1,4 @@
<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form" xmlns:i="jelly:fmt" xmlns:p="/lib/hudson/project">
<l:layout title="${it.displayName}">
<st:include page="sidepanel.jelly" />
@@ -1,6 +1,7 @@
<!--
Side panel for the tasks.
-->
<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form" xmlns:i="jelly:fmt">
<l:header>
<link rel="alternate" title="Hudson:${it.fullDisplayName} (all runs)" href="rssAll" type="application/rss+xml" />
@@ -1,3 +1,4 @@
<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form" xmlns:i="jelly:fmt" xmlns:local="local">
<d:taglib uri="local">
<d:tag name="lastRun">
@@ -1,3 +1,4 @@
<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:f="/lib/form">
<f:entry title="${%Project}" field="project">
<f:textbox />
@@ -1,3 +1,4 @@
<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form">
<f:entry>
<f:repeatableProperty field="configs" noAddButton="true" minimum="1" />
@@ -1,3 +1,4 @@
<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form">
<f:optionalBlock name="batch-tasks.on" title="${%Batch tasks}" checked="${!empty(instance.tasks)}"
help="/plugin/batch-task/help.html">
@@ -1,3 +1,4 @@
<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form">
<h3>${%Downstream Tasks}</h3>
<ul>
@@ -1,3 +1,4 @@
<?jelly escape-by-default='true'?>
<div>
This plugin adds the "task" action to the project for performing batch tasks on the server workspace.
</div>

This file was deleted.

Oops, something went wrong.
@@ -0,0 +1,34 @@
package hudson.plugins.batch_task;

import hudson.model.Computer;
import hudson.model.Node;
import org.junit.Rule;

import hudson.model.FreeStyleProject;

import org.junit.Test;
import org.jvnet.hudson.test.JenkinsRule;

public class BatchRunTest {

@Rule
public JenkinsRule r = new JenkinsRule();

@Test
public void testBasic() throws Exception {
// build on the slave
Computer computer = r.jenkins.createComputer();
Node node = computer.getNode();
FreeStyleProject freeStyleProject = r.createFreeStyleProject();
freeStyleProject.setAssignedNode(node);
r.assertBuildStatusSuccess(freeStyleProject.scheduleBuild2(0).get());

// add a batch task
BatchTask batchTask = new BatchTask("test", "echo hello");
BatchTaskProperty batchTaskProperty = new BatchTaskProperty(batchTask);
freeStyleProject.addProperty(batchTaskProperty);

// now this should fail
r.jenkins.getQueue().schedule(batchTask, 0).getFuture().get();
}
}
@@ -30,30 +30,38 @@
import hudson.model.Cause.UpstreamCause;
import hudson.model.Cause.UserCause;
import hudson.model.CauseAction;
import hudson.model.FreeStyleBuild;
import hudson.model.FreeStyleProject;
import hudson.model.Queue;
import hudson.model.Result;
import hudson.slaves.EnvironmentVariablesNodeProperty;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.JenkinsRule;
import static org.junit.Assert.*;

import java.util.concurrent.TimeUnit;

import org.jvnet.hudson.test.HudsonTestCase;

/**
* Tests for batch tasks plugin.
* @author Alan Harder
*/
public class BatchTaskTest extends HudsonTestCase {
public class BatchTaskTest {

@Rule
public JenkinsRule r = new JenkinsRule();

/**
* Verify redirect on attempt to run task when there are no builds.
*/
@Test
public void testNoBuilds() throws Exception {
FreeStyleProject p = createFreeStyleProject();
FreeStyleProject p = r.createFreeStyleProject();
p.addProperty(new BatchTaskProperty(new BatchTask("test", "echo hello")));
WebClient wc = new WebClient();
JenkinsRule.WebClient wc = r.createWebClient();
HtmlPage page = wc.getPage(p, "batchTasks/task/test/execute");
String path = page.getWebResponse().getUrl().getPath();
String path = page.getWebResponse().getWebRequest().getUrl().getPath();
assertTrue("should redirect to noBuilds page: " + path, path.endsWith("/noBuild"));
}

@@ -62,13 +70,15 @@ public void testNoBuilds() throws Exception {
* TASK_ID for this run, global and node properties, HUDSON_USER if triggered
* by a user.
*/
@Test
public void testExecute() throws Exception {
hudson.getGlobalNodeProperties().add(new EnvironmentVariablesNodeProperty(

r.jenkins.getGlobalNodeProperties().add(new EnvironmentVariablesNodeProperty(
new EnvironmentVariablesNodeProperty.Entry("GLOBAL", "global-property"),
new EnvironmentVariablesNodeProperty.Entry("OVERRIDE_ME", "foo")));
hudson.getNodeProperties().add(new EnvironmentVariablesNodeProperty(
r.jenkins.getNodeProperties().add(new EnvironmentVariablesNodeProperty(
new EnvironmentVariablesNodeProperty.Entry("OVERRIDE_ME", "bar")));
FreeStyleProject p = createFreeStyleProject("execute");
FreeStyleProject p = r.createFreeStyleProject("execute");
BatchTask task;
if (Functions.isWindows()) {
task = new BatchTask("test",
@@ -79,10 +89,12 @@ public void testExecute() throws Exception {
"echo \"$TASK_ID:$GLOBAL:$OVERRIDE_ME:$HUDSON_USER\"\n");
}
p.addProperty(new BatchTaskProperty(task));
p.scheduleBuild2(0).get();
new WebClient().getPage(p, "batchTasks/task/test/execute");
Queue.Item q = hudson.getQueue().getItem(task);
if (q!=null) q.getFuture().get(5, TimeUnit.SECONDS);
p.scheduleBuild2(0);
FreeStyleBuild freeStyleBuild = p.scheduleBuild2(0).get();
while (freeStyleBuild.isBuilding()) {
Thread.sleep(100);
}
r.createWebClient().getPage(p, "batchTasks/task/test/execute");
BatchRun run = task.getLastRun();
assertNotNull("task did not run", run);
CauseAction ca = run.getAction(CauseAction.class);
@@ -97,17 +109,18 @@ public void testExecute() throws Exception {
/**
* Verify UpstreamCause is added when a job triggers a task.
*/
@Test
public void testInvoker() throws Exception {
FreeStyleProject p = createFreeStyleProject("tasker");
FreeStyleProject p = r.createFreeStyleProject("tasker");
BatchTask task = new BatchTask("test", "echo hello\n");
p.addProperty(new BatchTaskProperty(task));
p.scheduleBuild2(0).get();
FreeStyleProject up = createFreeStyleProject("invoker");
FreeStyleProject up = r.createFreeStyleProject("invoker");
up.getPublishersList().add(new BatchTaskInvoker(
new BatchTaskInvoker.Config[] { new BatchTaskInvoker.Config(p.getFullName(), "test") },
Result.SUCCESS));
up.scheduleBuild2(0).get();
Queue.Item q = hudson.getQueue().getItem(task);
Queue.Item q = r.jenkins.getQueue().getItem(task);
if (q!=null) q.getFuture().get(5, TimeUnit.SECONDS);
BatchRun run = task.getLastRun();
assertNotNull("task did not run", run);
@@ -2,27 +2,36 @@

import hudson.model.FreeStyleProject;
import hudson.model.Queue;
import org.jvnet.hudson.test.Bug;
import org.jvnet.hudson.test.HudsonTestCase;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.Issue;
import org.jvnet.hudson.test.JenkinsRule;
import static org.junit.Assert.*;


/**
* @author Kohsuke Kawaguchi
*/
@Bug(2917)
public class RestartTest extends HudsonTestCase {
@Issue("2917")
public class RestartTest {

@Rule
public JenkinsRule r = new JenkinsRule();

@Test
public void testRestart() throws Exception {
FreeStyleProject p = createFreeStyleProject();
FreeStyleProject p = r.createFreeStyleProject();
p.scheduleBuild2(0).get();

// block the build so that nothing escapes from the queue
hudson.setNumExecutors(0);
r.jenkins.setNumExecutors(0);

BatchTask t = new BatchTask("test", "echo hello");
BatchTaskProperty bp = new BatchTaskProperty(t);
p.addProperty(bp);

// schedule a build but make sure it stays in the queue
Queue q = hudson.getQueue();
Queue q = r.jenkins.getQueue();
q.schedule(t,9999);
// reload the queue and make sure it persists fine
q.save();

0 comments on commit ec3d5cf

Please sign in to comment.
You can’t perform that action at this time.