Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #35 from abayer/pluggable-agent
[JENKINS-38433] Make the agent section pluggable.
- Loading branch information
Showing
36 changed files
with
1,337 additions
and
294 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
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,49 @@ | ||
<!-- | ||
~ The MIT License | ||
~ | ||
~ Copyright (c) 2016, CloudBees, Inc. | ||
~ | ||
~ Permission is hereby granted, free of charge, to any person obtaining a copy | ||
~ of this software and associated documentation files (the "Software"), to deal | ||
~ in the Software without restriction, including without limitation the rights | ||
~ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
~ copies of the Software, and to permit persons to whom the Software is | ||
~ furnished to do so, subject to the following conditions: | ||
~ | ||
~ The above copyright notice and this permission notice shall be included in | ||
~ all copies or substantial portions of the Software. | ||
~ | ||
~ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
~ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
~ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
~ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
~ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
~ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
~ THE SOFTWARE. | ||
--> | ||
|
||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>org.jenkinsci.plugins</groupId> | ||
<artifactId>pipeline-model-parent</artifactId> | ||
<version>0.5-SNAPSHOT</version> | ||
</parent> | ||
|
||
<groupId>org.jenkinsci.plugins</groupId> | ||
<artifactId>pipeline-model-declarative-agent</artifactId> | ||
<packaging>hpi</packaging> | ||
<name>Pipeline: Declarative Agent API</name> | ||
<description>API for declarative agents in Declarative Pipeline</description> | ||
<url>https://wiki.jenkins-ci.org/display/JENKINS/Pipeline+Model+Definition+Plugin</url> | ||
|
||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.jenkins-ci.plugins.workflow</groupId> | ||
<artifactId>workflow-cps</artifactId> | ||
<version>2.18</version> | ||
</dependency> | ||
</dependencies> | ||
|
||
</project> |
66 changes: 66 additions & 0 deletions
66
.../src/main/java/org/jenkinsci/plugins/pipeline/modeldefinition/agent/DeclarativeAgent.java
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,66 @@ | ||
/* | ||
* The MIT License | ||
* | ||
* Copyright (c) 2016, CloudBees, Inc. | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
* THE SOFTWARE. | ||
*/ | ||
|
||
package org.jenkinsci.plugins.pipeline.modeldefinition.agent; | ||
|
||
import hudson.ExtensionPoint; | ||
import hudson.model.AbstractDescribableImpl; | ||
import org.jenkinsci.plugins.scriptsecurity.sandbox.whitelists.Whitelisted; | ||
import org.jenkinsci.plugins.workflow.cps.CpsScript; | ||
import org.jenkinsci.plugins.workflow.cps.CpsThread; | ||
|
||
import java.io.Serializable; | ||
|
||
/** | ||
* Implementations for {@link DeclarativeAgentDescriptor} - pluggable agent backends for Declarative Pipelines. | ||
* | ||
* @author Andrew Bayer | ||
*/ | ||
public abstract class DeclarativeAgent extends AbstractDescribableImpl<DeclarativeAgent> implements Serializable, ExtensionPoint { | ||
|
||
/** | ||
* ONLY TO BE RUN FROM WITHIN A CPS THREAD. Parses the script source and loads it. | ||
* TODO: Decide if we want to cache the resulting objects or just *shrug* and re-parse them every time. | ||
* | ||
* @return The script object for this declarative agent. | ||
* @throws Exception if the script source cannot be loaded or we're called from outside a CpsThread. | ||
*/ | ||
@SuppressWarnings("unchecked") | ||
@Whitelisted | ||
public DeclarativeAgentScript getScript(CpsScript cpsScript) throws Exception { | ||
CpsThread c = CpsThread.current(); | ||
if (c == null) | ||
throw new IllegalStateException("Expected to be called from CpsThread"); | ||
|
||
return (DeclarativeAgentScript) cpsScript.getClass().getClassLoader() | ||
.loadClass(getDescriptor().getDeclarativeAgentScriptClass()) | ||
.getConstructor(CpsScript.class, DeclarativeAgent.class) | ||
.newInstance(cpsScript, this); | ||
} | ||
|
||
@Override | ||
public DeclarativeAgentDescriptor getDescriptor() { | ||
return (DeclarativeAgentDescriptor) super.getDescriptor(); | ||
} | ||
} |
Oops, something went wrong.