Skip to content
Permalink
Browse files

Merge remote-tracking branch 'origin/master' into JENKINS-37781

 Conflicts:
	pipeline-model-definition/src/main/groovy/org/jenkinsci/plugins/pipeline/modeldefinition/model/Stage.groovy
  • Loading branch information...
rsandell committed Nov 8, 2016
2 parents efe93be + eee41f8 commit 8c766601a1394bc2f5652c7a5fd8c6497563f265
Showing with 296 additions and 160 deletions.
  1. +1 −1 pipeline-model-declarative-agent/pom.xml
  2. +2 −3 ...ve-agent/src/main/java/org/jenkinsci/plugins/pipeline/modeldefinition/agent/DeclarativeAgent.java
  3. +15 −9 ...rc/main/java/org/jenkinsci/plugins/pipeline/modeldefinition/agent/DeclarativeAgentDescriptor.java
  4. +8 −13 pipeline-model-definition/pom.xml
  5. +5 −16 ...line-model-definition/src/main/groovy/org/jenkinsci/plugins/pipeline/modeldefinition/Utils.groovy
  6. +0 −4 ...roovy/org/jenkinsci/plugins/pipeline/modeldefinition/model/AbstractBuildConditionResponder.groovy
  7. +0 −6 ...odel-definition/src/main/groovy/org/jenkinsci/plugins/pipeline/modeldefinition/model/Agent.groovy
  8. +0 −5 ...inition/src/main/groovy/org/jenkinsci/plugins/pipeline/modeldefinition/model/JobProperties.groovy
  9. +0 −5 ...inition/src/main/groovy/org/jenkinsci/plugins/pipeline/modeldefinition/model/MappedClosure.groovy
  10. +0 −3 ...efinition/src/main/groovy/org/jenkinsci/plugins/pipeline/modeldefinition/model/NestedModel.groovy
  11. +0 −3 ...definition/src/main/groovy/org/jenkinsci/plugins/pipeline/modeldefinition/model/Parameters.groovy
  12. +0 −26 ...model-definition/src/main/groovy/org/jenkinsci/plugins/pipeline/modeldefinition/model/Root.groovy
  13. +0 −14 ...odel-definition/src/main/groovy/org/jenkinsci/plugins/pipeline/modeldefinition/model/Stage.groovy
  14. +0 −5 ...del-definition/src/main/groovy/org/jenkinsci/plugins/pipeline/modeldefinition/model/Stages.groovy
  15. +0 −4 ...definition/src/main/groovy/org/jenkinsci/plugins/pipeline/modeldefinition/model/StepsBlock.groovy
  16. +0 −4 ...odel-definition/src/main/groovy/org/jenkinsci/plugins/pipeline/modeldefinition/model/Tools.groovy
  17. +0 −3 ...l-definition/src/main/groovy/org/jenkinsci/plugins/pipeline/modeldefinition/model/Triggers.groovy
  18. +5 −20 ...odel-definition/src/main/java/org/jenkinsci/plugins/pipeline/modeldefinition/ModelStepLoader.java
  19. +0 −4 ...ition/src/main/java/org/jenkinsci/plugins/pipeline/modeldefinition/agent/impl/DockerPipeline.java
  20. +80 −0 .../java/org/jenkinsci/plugins/pipeline/modeldefinition/agent/impl/DockerPipelineFromDockerfile.java
  21. +0 −3 ...del-definition/src/main/java/org/jenkinsci/plugins/pipeline/modeldefinition/agent/impl/Label.java
  22. +3 −3 ...definition/src/main/java/org/jenkinsci/plugins/pipeline/modeldefinition/model/BuildCondition.java
  23. +60 −0 ...g/jenkinsci/plugins/pipeline/modeldefinition/agent/impl/DockerPipelineFromDockerfileScript.groovy
  24. +2 −1 ...definition/src/test/java/org/jenkinsci/plugins/pipeline/modeldefinition/AbstractModelDefTest.java
  25. +38 −1 ...line-model-definition/src/test/java/org/jenkinsci/plugins/pipeline/modeldefinition/AgentTest.java
  26. +1 −1 ...-model-definition/src/test/java/org/jenkinsci/plugins/pipeline/modeldefinition/ValidatorTest.java
  27. +0 −3 .../test/java/org/jenkinsci/plugins/pipeline/modeldefinition/agent/impl/LabelAndOtherFieldAgent.java
  28. +38 −0 pipeline-model-definition/src/test/resources/fromAlternateDockerfile.groovy
  29. +38 −0 pipeline-model-definition/src/test/resources/fromDockerfile.groovy
@@ -42,7 +42,7 @@
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-cps</artifactId>
<version>2.18</version>
<version>2.21</version>
</dependency>
</dependencies>

@@ -26,7 +26,6 @@

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;

@@ -47,13 +46,13 @@
* @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()
return (DeclarativeAgentScript) cpsScript.getClass()
.getClassLoader()
.loadClass(getDescriptor().getDeclarativeAgentScriptClass())
.getConstructor(CpsScript.class, DeclarativeAgent.class)
.newInstance(cpsScript, this);
@@ -25,12 +25,15 @@

import hudson.ExtensionList;
import hudson.model.Descriptor;
import org.jenkinsci.plugins.scriptsecurity.sandbox.whitelists.Whitelisted;
import org.jenkinsci.plugins.structs.SymbolLookup;
import org.jenkinsci.plugins.structs.describable.DescribableModel;

import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
@@ -43,7 +46,7 @@
public abstract class DeclarativeAgentDescriptor extends Descriptor<DeclarativeAgent> {

/**
* The name for this agent type. Should match the {@code Symbol} on the class.
* The name for this agent type. Defaults to the first string in the {@code Symbol} on the class.
*
* @return The name.
*/
@@ -57,7 +60,8 @@
}

/**
* The full package and class name for the {@link DeclarativeAgentScript} class corresponding to this.
* The full package and class name for the {@link DeclarativeAgentScript} class corresponding to this. Defaults to
* the {@link DeclarativeAgent} class name with "Script" appended to the end.
*
* @return The class name, defaulting to the {@link DeclarativeAgent} {@link #clazz} class name with "Script" appended.
*/
@@ -86,6 +90,11 @@ public DeclarativeAgent newInstance() throws Exception {
return clazz.newInstance();
}

/**
* Get all {@link DeclarativeAgentDescriptor}s.
*
* @return a list of all {@link DeclarativeAgentDescriptor}s registered.`
*/
public static ExtensionList<DeclarativeAgentDescriptor> all() {
return ExtensionList.lookup(DeclarativeAgentDescriptor.class);
}
@@ -129,8 +138,7 @@ public DeclarativeAgent newInstance() throws Exception {
* @param name The name for the descriptor to look up
* @return The corresponding descriptor or null if not found.
*/
@Whitelisted
public static @CheckForNull DeclarativeAgentDescriptor byName(@Nonnull String name) {
public static @Nullable DeclarativeAgentDescriptor byName(@Nonnull String name) {
return (DeclarativeAgentDescriptor) SymbolLookup.get().findDescriptor(DeclarativeAgent.class, name);
}

@@ -142,9 +150,8 @@ public DeclarativeAgent newInstance() throws Exception {
* @return The instantiated {@link DeclarativeAgent} instance, or null if the name isn't found.
* @throws Exception
*/
@Whitelisted
public static @CheckForNull DeclarativeAgent instanceForName(@Nonnull String name,
Map<String,Object> arguments) throws Exception {
public static @Nullable DeclarativeAgent instanceForName(@Nonnull String name,
Map<String,Object> arguments) throws Exception {
DeclarativeAgentDescriptor descriptor = byName(name);

if (descriptor != null) {
@@ -162,7 +169,6 @@ public DeclarativeAgent newInstance() throws Exception {
* @return The instantiated {@link DeclarativeAgent} instance.
* @throws Exception
*/
@Whitelisted
public static @Nonnull DeclarativeAgent instanceForDescriptor(@Nonnull DeclarativeAgentDescriptor descriptor,
Map<String,Object> arguments) throws Exception {
if (zeroArgModels().keySet().contains(descriptor.getName())) {
@@ -64,17 +64,17 @@
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-cps</artifactId>
<version>2.18</version>
<version>2.21</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-job</artifactId>
<version>2.6</version>
<version>2.8</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-multibranch</artifactId>
<version>2.8</version>
<version>2.9</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
@@ -84,12 +84,12 @@
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-basic-steps</artifactId>
<version>2.1</version>
<version>2.2</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-durable-task-step</artifactId>
<version>2.4</version>
<version>2.5</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
@@ -99,18 +99,13 @@
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>docker-workflow</artifactId>
<version>1.8</version>
<version>1.9</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>structs</artifactId>
<version>1.5</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>script-security</artifactId>
<version>1.22</version>
</dependency>

<!-- JSON schema stuff -->
<dependency>
@@ -148,7 +143,7 @@
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-cps-global-lib</artifactId>
<version>2.3</version>
<version>2.4</version>
<scope>test</scope>
</dependency>

@@ -176,7 +171,7 @@
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-support</artifactId>
<version>2.2</version>
<version>2.10</version>
<classifier>tests</classifier>
<scope>test</scope>
</dependency>
@@ -31,15 +31,13 @@ import edu.umd.cs.findbugs.annotations.SuppressFBWarnings
import hudson.ExtensionList
import hudson.model.Describable
import hudson.model.Descriptor
import hudson.triggers.TriggerDescriptor
import org.apache.commons.codec.digest.DigestUtils
import org.jenkinsci.plugins.pipeline.modeldefinition.actions.ExecutionModelAction
import org.jenkinsci.plugins.pipeline.modeldefinition.ast.ModelASTPipelineDef
import org.jenkinsci.plugins.pipeline.modeldefinition.ast.ModelASTStages
import org.jenkinsci.plugins.pipeline.modeldefinition.model.MethodsToList
import org.jenkinsci.plugins.pipeline.modeldefinition.parser.Converter
import org.jenkinsci.plugins.scriptsecurity.sandbox.whitelists.Whitelisted
import org.jenkinsci.plugins.structs.SymbolLookup
import org.jenkinsci.plugins.structs.describable.UninstantiatedDescribable
import org.jenkinsci.plugins.workflow.cps.CpsScript
import org.jenkinsci.plugins.workflow.job.WorkflowRun

@@ -66,7 +64,6 @@ public class Utils {
* we'll get the actual name from actualFieldName(...)
* @return True if the field exists and is of the given type.
*/
@Whitelisted
public static boolean isFieldA(Class fieldType, Class actualClass, String fieldName) {
def actualFieldName = actualFieldName(actualClass, fieldName)
def realFieldType = actualClass.metaClass.getMetaProperty(actualFieldName)?.type
@@ -85,7 +82,6 @@ public class Utils {
* @param fieldName The original field name, which could need to be pluralized.
* @return The real field name, pluralized if necessary, or null if not found.
*/
@Whitelisted
public static String actualFieldName(Class actualClass, String fieldName) {
if (actualClass.metaClass.getMetaProperty(fieldName) != null) {
return fieldName
@@ -103,7 +99,6 @@ public class Utils {
* @param fieldName The field name we're looking for, which could get pluralized.
* @return The class of the field in the inspected class, or the class contained in the list or map.
*/
@Whitelisted
public static Class actualFieldType(Class actualClass, String fieldName) {
def actualFieldName = actualFieldName(actualClass, fieldName)
if (actualFieldName == null) {
@@ -131,7 +126,6 @@ public class Utils {
* @param c A class.
* @return The parameterized type argument for the class, if it's a {@link MethodsToList} class. Null otherwise.
*/
@Whitelisted
public static Class<Describable> getMethodsToListType(Class c) {
Class retClass
c.genericInterfaces.each { Type t ->
@@ -152,7 +146,6 @@ public class Utils {
* @param o The object to check
* @return True if the object is an instance of the class, false otherwise
*/
@Whitelisted
public static boolean instanceOfWrapper(Class c, Object o) {
return c.isInstance(o)
}
@@ -164,17 +157,10 @@ public class Utils {
* @param o The class to check
* @return True if o can be assigned to c, false otherwise
*/
@Whitelisted
public static boolean assignableFromWrapper(Class c, Class o) {
return c.isAssignableFrom(o)
}

@Whitelisted
public static Object[] toObjectArray(List<Object> origList) {
return origList.toArray()
}

@Whitelisted
public static boolean hasScmContext(CpsScript script) {
try {
// Just rely on SCMVar's own context-checking (via CpsScript) rather than brewing our own.
@@ -186,7 +172,6 @@ public class Utils {
}
}

@Whitelisted
static void attachExecutionModel(CpsScript script) {
WorkflowRun r = script.$build()
ModelASTPipelineDef model = Converter.parseFromCpsScript(script)
@@ -198,6 +183,10 @@ public class Utils {
r.addAction(new ExecutionModelAction(stages))
}

public static String stringToSHA1(String s) {
return DigestUtils.sha1Hex(s)
}

/**
* Creates and sets the loading for a cache of {@link Describable}s descending from the given descriptor type.
*
@@ -25,7 +25,6 @@ package org.jenkinsci.plugins.pipeline.modeldefinition.model

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings

import org.jenkinsci.plugins.scriptsecurity.sandbox.whitelists.Whitelisted
import org.jenkinsci.plugins.workflow.job.WorkflowRun
import org.jenkinsci.plugins.workflow.support.steps.build.RunWrapper

@@ -41,7 +40,6 @@ public abstract class AbstractBuildConditionResponder<T extends AbstractBuildCon


@Override
@Whitelisted
public void modelFromMap(Map<String,Object> inMap) {

inMap.each { conditionName, conditionClosure ->
@@ -54,8 +52,6 @@ public abstract class AbstractBuildConditionResponder<T extends AbstractBuildCon
}
}


@Whitelisted
public List<Closure> satisfiedConditions(Object runWrapperObj) {
RunWrapper runWrapper = (RunWrapper)runWrapperObj
WorkflowRun run = (WorkflowRun)runWrapper.getRawBuild()
@@ -29,7 +29,6 @@ import groovy.transform.ToString
import org.jenkinsci.plugins.pipeline.modeldefinition.agent.DeclarativeAgent
import org.jenkinsci.plugins.pipeline.modeldefinition.agent.DeclarativeAgentDescriptor
import org.jenkinsci.plugins.pipeline.modeldefinition.agent.impl.None
import org.jenkinsci.plugins.scriptsecurity.sandbox.whitelists.Whitelisted


/**
@@ -42,18 +41,15 @@ import org.jenkinsci.plugins.scriptsecurity.sandbox.whitelists.Whitelisted
@EqualsAndHashCode
@SuppressFBWarnings(value="SE_NO_SERIALVERSIONID")
public class Agent implements Serializable {
@Whitelisted
Map<String,String> arguments = [:]

@Whitelisted
public Agent(Map<String,String> args) {
this.arguments.putAll(args)
}

/**
* Special constructor for the no-additional-arguments agent types, i.e., none and any
*/
@Whitelisted
public Agent(String s) {
this.arguments.put(s, "true")
}
@@ -63,7 +59,6 @@ public class Agent implements Serializable {
*
* @return The instantiated declarative agent or null if not found.
*/
@Whitelisted
public DeclarativeAgent getDeclarativeAgent() {
DeclarativeAgentDescriptor foundDescriptor = DeclarativeAgentDescriptor.all().find { d ->
arguments.containsKey(d.getName())
@@ -76,7 +71,6 @@ public class Agent implements Serializable {
}
}

@Whitelisted
public boolean hasAgent() {
DeclarativeAgent a = getDeclarativeAgent()
return a != null && !None.class.isInstance(a)
@@ -32,9 +32,6 @@ import groovy.transform.ToString
import hudson.model.JobProperty
import hudson.model.JobPropertyDescriptor
import org.jenkinsci.plugins.pipeline.modeldefinition.Utils
import org.jenkinsci.plugins.scriptsecurity.sandbox.whitelists.Whitelisted
import org.jenkinsci.plugins.structs.describable.UninstantiatedDescribable
import org.jenkinsci.plugins.workflow.cps.CpsScript

import javax.annotation.Nonnull

@@ -72,7 +69,6 @@ public class JobProperties implements Serializable, MethodsToList<JobProperty> {
*
* @return A map of valid property type keys to their actual type IDs.
*/
@Whitelisted
public static Map<String,String> getAllowedPropertyTypes() {
return propertyTypeCache.get(CACHE_KEY)
}
@@ -83,7 +79,6 @@ public class JobProperties implements Serializable, MethodsToList<JobProperty> {
* @param key The key to look up.
* @return The type ID for that key, if it's in the property types cache.
*/
@Whitelisted
public static String typeForKey(@Nonnull String key) {
return getAllowedPropertyTypes().get(key)
}

0 comments on commit 8c76660

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