Skip to content

Commit

Permalink
[JENKINS-48050] declarative « container » agent
Browse files Browse the repository at this point in the history
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
  • Loading branch information
ndeloof committed Feb 28, 2018
1 parent 099e1df commit 2e2c79f
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 2 deletions.
38 changes: 36 additions & 2 deletions pom.xml
Expand Up @@ -27,6 +27,7 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.level>8</java.level>
<groovy.version>2.4.7</groovy.version>
<jenkins.version>2.60.3</jenkins.version>
</properties>

Expand Down Expand Up @@ -74,7 +75,7 @@
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-step-api</artifactId>
<version>2.13</version>
<version>2.14</version>
<optional>true</optional>
</dependency>
<dependency>
Expand Down Expand Up @@ -111,10 +112,15 @@
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-step-api</artifactId>
<version>2.13</version>
<version>2.14</version>
<optional>true</optional>
</dependency>

<dependency>
<groupId>org.jenkinsci.plugins</groupId>
<artifactId>pipeline-model-extensions</artifactId>
<version>1.2.7</version>
</dependency>

<dependency>
<groupId>com.kohlschutter.junixsocket</groupId>
Expand Down Expand Up @@ -185,6 +191,16 @@
</dependency>
</dependencies>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>structs</artifactId>
<version>1.9</version>
</dependency>
</dependencies>
</dependencyManagement>

<build>
<plugins>
<plugin>
Expand All @@ -207,6 +223,24 @@
<compatibleSinceVersion>0.17</compatibleSinceVersion>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.gmaven</groupId>
<artifactId>gmaven-plugin</artifactId>
<version>1.5-jenkins-3</version>
<configuration>
<providerSelection>1.${java.level}</providerSelection>
</configuration>
<executions>
<execution>
<goals>
<goal>generateStubs</goal>
<goal>compile</goal>
<goal>generateTestStubs</goal>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>

</plugins>
</build>
Expand Down
@@ -0,0 +1,24 @@
package io.jenkins.docker.pipeline;

import org.jenkinsci.plugins.pipeline.modeldefinition.agent.DeclarativeAgentScript
import org.jenkinsci.plugins.workflow.cps.CpsScript


/**
* @author <a href="mailto:nicolas.deloof@gmail.com">Nicolas De Loof</a>
*/
class DockerAgentScript extends DeclarativeAgentScript<DockerAgent> {

DockerAgentScript(CpsScript s, DockerAgent dockerAgent) {
super(s, dockerAgent)
}

@Override
Closure run(Closure closure) {
return {
script.dockerNode("unix://var/run/docker.sock", describable.image, "/tmp") {
body.call()
}
}
}
}
27 changes: 27 additions & 0 deletions src/main/java/io/jenkins/docker/pipeline/DockerAgent.java
@@ -0,0 +1,27 @@
package io.jenkins.docker.pipeline;

import hudson.Extension;
import org.jenkinsci.Symbol;
import org.jenkinsci.plugins.pipeline.modeldefinition.agent.DeclarativeAgent;
import org.jenkinsci.plugins.pipeline.modeldefinition.agent.DeclarativeAgentDescriptor;
import org.kohsuke.stapler.DataBoundConstructor;

import javax.annotation.Nonnull;

/**
* @author <a href="mailto:nicolas.deloof@gmail.com">Nicolas De Loof</a>
*/
public class DockerAgent extends DeclarativeAgent<DockerAgent> {

private final String image;

@DataBoundConstructor
public DockerAgent(@Nonnull String image) {
this.image = image;
}

@Extension(ordinal = 1000, optional = true) @Symbol("container")
public static class DescriptorImpl extends DeclarativeAgentDescriptor<DockerAgent> {
}

}

0 comments on commit 2e2c79f

Please sign in to comment.