Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[JENKINS-48050] declarative « container » agent
- Loading branch information
Showing
4 changed files
with
111 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
src/main/groovy/io/jenkins/docker/pipeline/DockerAgentScript.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> { | ||
} | ||
|
||
} |
24 changes: 24 additions & 0 deletions
24
src/main/java/io/jenkins/docker/pipeline/DockerAgentScript.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() | ||
} | ||
} | ||
} | ||
} |