Skip to content

Commit

Permalink
Merge branch 'master' of github.com:jenkinsci/pipeline-model-definiti…
Browse files Browse the repository at this point in the history
…on-plugin into JENKINS-48523
  • Loading branch information
rsandell committed Mar 15, 2018
2 parents 1dfa65c + 9cc0da1 commit 75930fc
Show file tree
Hide file tree
Showing 26 changed files with 512 additions and 56 deletions.
6 changes: 3 additions & 3 deletions Jenkinsfile
Expand Up @@ -11,7 +11,7 @@ pipeline {

// Set log rotation, timeout and timestamps in the console
options {
buildDiscarder(logRotator(numToKeepStr:'20'))
buildDiscarder(logRotator(numToKeepStr:'10'))
timestamps()
timeout(time: 90, unit: 'MINUTES')
}
Expand All @@ -30,7 +30,7 @@ pipeline {
parallel {
stage("linux") {
agent {
label "java"
label "highmem"
}
steps {
sh 'mvn clean install -Dmaven.test.failure.ignore=true'
Expand Down Expand Up @@ -66,7 +66,7 @@ pipeline {
}
stage("linux-newer-core") {
agent {
label "java"
label "highmem"
}
steps {
sh "mvn clean install -Dmaven.test.failure.ignore=true -Djava.level=8 -Djenkins.version=${NEWER_CORE_VERSION}"
Expand Down
Expand Up @@ -115,47 +115,60 @@ public String toString() {
}

public static ModelASTValue fromConstant(final Object o, Object sourceLocation) {
return new ModelASTValue(sourceLocation, o) {
@Override
public boolean isLiteral() {
return true;
}
return new ConstantValue(sourceLocation, o);
}

public static ModelASTValue fromGString(final String gstring, Object sourceLocation) {
return new GStringValue(sourceLocation, gstring);
}

@Override
public String toGroovy() {
if (getValue() instanceof String) {
String str = (String) getValue();
str = str.replace("\\", "\\\\");
if (str.indexOf('\n') == -1) {
return "'" + (str.replace("'", "\\'")) + "'";
} else {
return "'''" + (str.replace("'", "\\'")) + "'''";
}
} else if (getValue() != null) {
return getValue().toString();
private static final class ConstantValue extends ModelASTValue {
ConstantValue(Object sourceLocation, Object v) {
super(sourceLocation, v);
}

@Override
public boolean isLiteral() {
return true;
}

@Override
public String toGroovy() {
if (getValue() instanceof String) {
String str = (String) getValue();
str = str.replace("\\", "\\\\");
if (str.indexOf('\n') == -1) {
return "'" + (str.replace("'", "\\'")) + "'";
} else {
return null;
return "'''" + (str.replace("'", "\\'")) + "'''";
}
} else if (getValue() != null) {
return getValue().toString();
} else {
return null;
}
};
}
}

public static ModelASTValue fromGString(final String gstring, Object sourceLocation) {
return new ModelASTValue(sourceLocation, gstring) {
@Override
public boolean isLiteral() {
return false;
}
private static final class GStringValue extends ModelASTValue {
GStringValue(Object sourceLocation, Object v) {
super(sourceLocation, v);
}

@Override
public String toGroovy() {
String gstring = (String)getValue();
if (gstring.startsWith("${") && gstring.endsWith("}")) {
return gstring.substring(2, gstring.length() - 1);
} else {
return gstring;
}
@Override
public boolean isLiteral() {
return false;
}

@Override
public String toGroovy() {
String gstring = (String)getValue();
if (gstring.startsWith("${") && gstring.endsWith("}")) {
return gstring.substring(2, gstring.length() - 1);
} else {
return gstring;
}
};
}

}
}
Expand Up @@ -26,11 +26,13 @@ package org.jenkinsci.plugins.pipeline.modeldefinition.model
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings
import groovy.transform.EqualsAndHashCode
import groovy.transform.ToString
import org.jenkinsci.plugins.pipeline.modeldefinition.agent.AbstractDockerAgent
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.pipeline.modeldefinition.options.DeclarativeOption
import org.jenkinsci.plugins.pipeline.modeldefinition.options.impl.CheckoutToSubdirectory
import org.jenkinsci.plugins.pipeline.modeldefinition.options.impl.ContainerPerStage
import org.jenkinsci.plugins.pipeline.modeldefinition.options.impl.SkipDefaultCheckout
import org.jenkinsci.plugins.scriptsecurity.sandbox.whitelists.Whitelisted
import org.jenkinsci.plugins.structs.SymbolLookup
Expand Down Expand Up @@ -102,6 +104,18 @@ class Agent extends MappedClosure<Object,Agent> implements Serializable {
if (subdir?.subdirectory != null && subdir?.subdirectory != "") {
a.setSubdirectory(subdir.subdirectory)
}
if (a instanceof AbstractDockerAgent) {
ContainerPerStage containerPerStage = (ContainerPerStage) options.get("newContainerPerStage")
if (containerPerStage != null) {
if (context instanceof Root) {
// If we're on the root, make sure we switch to basically just doing a label
a.containerPerStageRoot = true
} else if (context instanceof Stage && context.agent == null) {
// While if we're on a stage that doesn't have an explicit agent, make sure we reuse the node
a.reuseNode = true
}
}
}
}
a.setDoCheckout(doCheckout)

Expand Down
Expand Up @@ -29,6 +29,8 @@ import org.jenkinsci.Symbol
import org.jenkinsci.plugins.pipeline.modeldefinition.model.BuildCondition
import org.jenkinsci.plugins.workflow.job.WorkflowRun

import javax.annotation.Nonnull

/**
* A {@link BuildCondition} for matching aborted builds.
*
Expand All @@ -37,7 +39,7 @@ import org.jenkinsci.plugins.workflow.job.WorkflowRun
@Extension(ordinal=800d) @Symbol("aborted")
class Aborted extends BuildCondition {
@Override
boolean meetsCondition(WorkflowRun r) {
boolean meetsCondition(@Nonnull WorkflowRun r) {
Result execResult = getExecutionResult(r)
return execResult == Result.ABORTED || r.getResult() == Result.ABORTED
}
Expand Down
Expand Up @@ -28,6 +28,8 @@ import org.jenkinsci.Symbol
import org.jenkinsci.plugins.pipeline.modeldefinition.model.BuildCondition
import org.jenkinsci.plugins.workflow.job.WorkflowRun

import javax.annotation.Nonnull

/**
* A {@link BuildCondition} for matching all builds regardless of status.
*
Expand All @@ -36,7 +38,7 @@ import org.jenkinsci.plugins.workflow.job.WorkflowRun
@Extension(ordinal=1000d) @Symbol("always")
class Always extends BuildCondition {
@Override
boolean meetsCondition(WorkflowRun r) {
boolean meetsCondition(@Nonnull WorkflowRun r) {
return true
}

Expand Down
Expand Up @@ -29,6 +29,8 @@ import org.jenkinsci.Symbol
import org.jenkinsci.plugins.pipeline.modeldefinition.model.BuildCondition
import org.jenkinsci.plugins.workflow.job.WorkflowRun

import javax.annotation.Nonnull

/**
* A {@link BuildCondition} for matching builds with a different status than the previous build.
*
Expand All @@ -37,14 +39,13 @@ import org.jenkinsci.plugins.workflow.job.WorkflowRun
@Extension(ordinal=900d) @Symbol("changed")
class Changed extends BuildCondition {
@Override
boolean meetsCondition(WorkflowRun r) {
Result execResult = getExecutionResult(r)
boolean meetsCondition(@Nonnull WorkflowRun r) {
// Only look at the previous completed build.
WorkflowRun prev = r.getPreviousCompletedBuild()

// Get the *worst* result of either the execution or the run. If the run's result is null, that's effectively
// SUCCESS.
Result runResult = execResult.combine(r.getResult() ?: Result.SUCCESS)
Result runResult = combineResults(r)

// If there's no previous build, we're inherently changed.
if (prev == null) {
Expand Down
Expand Up @@ -29,6 +29,8 @@ import org.jenkinsci.Symbol
import org.jenkinsci.plugins.pipeline.modeldefinition.model.BuildCondition
import org.jenkinsci.plugins.workflow.job.WorkflowRun

import javax.annotation.Nonnull

/**
* A {@link BuildCondition} for matching failed builds.
*
Expand All @@ -37,7 +39,7 @@ import org.jenkinsci.plugins.workflow.job.WorkflowRun
@Extension(ordinal=700d) @Symbol("failure")
class Failure extends BuildCondition {
@Override
boolean meetsCondition(WorkflowRun r) {
boolean meetsCondition(@Nonnull WorkflowRun r) {
Result execResult = getExecutionResult(r)
return execResult == Result.FAILURE || r.getResult() == Result.FAILURE
}
Expand Down
@@ -0,0 +1,66 @@
/*
* The MIT License
*
* Copyright (c) 2018, 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.model.conditions

import hudson.Extension
import hudson.model.Result
import org.jenkinsci.Symbol
import org.jenkinsci.plugins.pipeline.modeldefinition.model.BuildCondition
import org.jenkinsci.plugins.workflow.job.WorkflowRun

import javax.annotation.Nonnull

/**
* A {@link BuildCondition} for matching builds where the previous build was not SUCCESS but the current build is.
*
* @author Andrew Bayer
*/
@Extension(ordinal=890d) @Symbol("fixed")
class Fixed extends BuildCondition {
@Override
boolean meetsCondition(@Nonnull WorkflowRun r) {
// Only look at the previous completed build.
WorkflowRun prev = r.getPreviousCompletedBuild()

// Get the *worst* result of either the execution or the run. If the run's result is null, that's effectively
// SUCCESS.
Result runResult = combineResults(r)

// If there's no previous build, we can't exactly be fixed, can we?
if (prev == null) {
return false
} else {
return runResult == Result.SUCCESS && prev.getResult() in [Result.FAILURE, Result.UNSTABLE]
}
}

@Override
String getDescription() {
return Messages.Fixed_Description()
}


static final long serialVersionUID = 1L

}
Expand Up @@ -29,6 +29,8 @@ import org.jenkinsci.Symbol
import org.jenkinsci.plugins.pipeline.modeldefinition.model.BuildCondition
import org.jenkinsci.plugins.workflow.job.WorkflowRun

import javax.annotation.Nonnull

/**
* A {@link BuildCondition} for matching unbuilt builds, such as those stopped by milestones.
*
Expand All @@ -37,7 +39,7 @@ import org.jenkinsci.plugins.workflow.job.WorkflowRun
@Extension(ordinal=400d) @Symbol("notBuilt")
class NotBuilt extends BuildCondition {
@Override
boolean meetsCondition(WorkflowRun r) {
boolean meetsCondition(@Nonnull WorkflowRun r) {
Result execResult = getExecutionResult(r)
return execResult == Result.NOT_BUILT || r.getResult() == Result.NOT_BUILT
}
Expand Down
@@ -0,0 +1,66 @@
/*
* The MIT License
*
* Copyright (c) 2018, 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.model.conditions

import hudson.Extension
import hudson.model.Result
import org.jenkinsci.Symbol
import org.jenkinsci.plugins.pipeline.modeldefinition.model.BuildCondition
import org.jenkinsci.plugins.workflow.job.WorkflowRun

import javax.annotation.Nonnull

/**
* A {@link BuildCondition} for matching builds where the previous build was better than the current build.
*
* @author Andrew Bayer
*/
@Extension(ordinal=880d) @Symbol("regression")
class Regression extends BuildCondition {
@Override
boolean meetsCondition(@Nonnull WorkflowRun r) {
// Only look at the previous completed build.
WorkflowRun prev = r.getPreviousCompletedBuild()

// Get the *worst* result of either the execution or the run. If the run's result is null, that's effectively
// SUCCESS.
Result runResult = combineResults(r)

// If there's no previous build, we can't exactly be regressing, can we?
if (prev == null) {
return false
} else {
return runResult.isWorseThan(prev.getResult())
}
}

@Override
String getDescription() {
return Messages.Regression_Description()
}


static final long serialVersionUID = 1L

}

0 comments on commit 75930fc

Please sign in to comment.