Skip to content
Permalink
Browse files
[JENKINS-48050] declarative « container » agent
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
  • Loading branch information
ndeloof committed Feb 26, 2018
1 parent 6acd9e8 commit 65dce18da936fbeea34d89245595d085866dd725
Showing with 87 additions and 2 deletions.
  1. +36 −2 pom.xml
  2. +24 −0 src/main/groovy/io/jenkins/docker/pipeline/DockerAgentScript.groovy
  3. +27 −0 src/main/java/io/jenkins/docker/pipeline/DockerAgent.java
38 pom.xml
@@ -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>

@@ -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>
@@ -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>
@@ -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>
@@ -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>
@@ -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()
}
}
}
}
@@ -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 65dce18

Please sign in to comment.