Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JENKINS-58732] Complete cleanup of pipeline-model-definition dep #230

Merged
merged 5 commits into from
Feb 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 35 additions & 12 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>4.6</version>
<version>4.12</version>
<relativePath />
</parent>
<artifactId>docker-workflow</artifactId>
Expand All @@ -31,9 +31,9 @@
<properties>
<revision>1.26</revision>
<changelist>-SNAPSHOT</changelist>
<jenkins.version>2.190.1</jenkins.version>
<jenkins.version>2.190.3</jenkins.version>
<java.level>8</java.level>
<pipeline-model-definition-plugin.version>1.5.1</pipeline-model-definition-plugin.version>
<pipeline-model-definition-plugin.version>1.8.1</pipeline-model-definition-plugin.version>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably could be removed at this point, picking up bom version. Just have not checked recently.

</properties>
<repositories>
<repository>
Expand All @@ -52,10 +52,41 @@
<dependency>
<groupId>io.jenkins.tools.bom</groupId>
<artifactId>bom-2.190.x</artifactId>
<version>11</version>
<version>14</version>
<scope>import</scope>
<type>pom</type>
</dependency>
<dependency> <!-- TODO until we are on 2.222.x and can use bom 22+ -->
<groupId>org.jenkinsci.plugins</groupId>
<artifactId>pipeline-model-api</artifactId>
<version>${pipeline-model-definition-plugin.version}</version>
</dependency>
<dependency>
<groupId>org.jenkinsci.plugins</groupId>
<artifactId>pipeline-model-definition</artifactId>
<version>${pipeline-model-definition-plugin.version}</version>
</dependency>
<dependency>
<groupId>org.jenkinsci.plugins</groupId>
<artifactId>pipeline-model-definition</artifactId>
<classifier>tests</classifier>
<version>${pipeline-model-definition-plugin.version}</version>
</dependency>
<dependency>
<groupId>org.jenkinsci.plugins</groupId>
<artifactId>pipeline-model-extensions</artifactId>
<version>${pipeline-model-definition-plugin.version}</version>
</dependency>
<dependency>
<groupId>org.jenkinsci.plugins</groupId>
<artifactId>pipeline-stage-tags-metadata</artifactId>
<version>${pipeline-model-definition-plugin.version}</version>
</dependency>
<dependency> <!-- TODO bom problem -->
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>jackson2-api</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
Expand All @@ -80,11 +111,6 @@
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-step-api</artifactId>
</dependency>
<dependency>
<groupId>org.jenkinsci.plugins</groupId>
<artifactId>pipeline-model-extensions</artifactId>
<version>${pipeline-model-definition-plugin.version}</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>cloudbees-folder</artifactId>
Expand Down Expand Up @@ -126,8 +152,6 @@
<dependency>
<groupId>org.jenkinsci.plugins</groupId>
<artifactId>pipeline-model-definition</artifactId>
<version>${pipeline-model-definition-plugin.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
Expand All @@ -149,7 +173,6 @@
<dependency>
<groupId>org.jenkinsci.plugins</groupId>
<artifactId>pipeline-model-definition</artifactId>
<version>${pipeline-model-definition-plugin.version}</version>
<classifier>tests</classifier>
<scope>test</scope>
</dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,18 @@

import hudson.model.Run;
import org.apache.commons.lang.StringUtils;
import org.jenkinsci.plugins.docker.workflow.declarative.DockerPropertiesProvider;
import org.jenkinsci.plugins.pipeline.modeldefinition.agent.impl.Label;
import org.jenkinsci.plugins.pipeline.modeldefinition.withscript.WithScriptScript;
import org.jenkinsci.plugins.scriptsecurity.sandbox.whitelists.Whitelisted;
import org.jenkinsci.plugins.workflow.cps.CpsFlowExecution;
import org.jenkinsci.plugins.workflow.cps.CpsScript;
import org.jenkinsci.plugins.workflow.cps.CpsThread;
import org.jenkinsci.plugins.workflow.flow.FlowExecutionOwner;

import javax.annotation.Nullable;
import java.io.IOException;
import java.io.Serializable;
import java.util.Collections;

/**
* @see org.jenkinsci.plugins.docker.workflow.declarative.DockerLabelProvider
Expand Down Expand Up @@ -82,6 +85,16 @@ public static String getLabel(@Nullable String override) {
return null;
}

@Whitelisted
public static WithScriptScript<?> getLabelScript(AbstractDockerAgent<?> describable, CpsScript script) throws Exception {
String targetLabel = getLabel(describable.getLabel());
Label l = (Label) Label.DescriptorImpl.instanceForName("label", Collections.singletonMap("label", targetLabel));
l.copyFlags(describable);
l.setCustomWorkspace(describable.getCustomWorkspace());
return l.getScript(script);

}

@Whitelisted
public static String getRegistryUrl() {
return getRegistryUrl(null);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
package org.jenkinsci.plugins.docker.workflow.declarative

import hudson.FilePath
import jenkins.model.Jenkins
import org.jenkinsci.plugins.pipeline.modeldefinition.agent.DeclarativeAgentScript
import org.jenkinsci.plugins.workflow.cps.CpsScript

Expand All @@ -43,25 +42,16 @@ abstract class AbstractDockerPipelineScript<A extends AbstractDockerAgent<A>> ex
configureRegistry(body).call()
}
} else if (describable.containerPerStageRoot) {
return getLabelScript().run {
return DeclarativeDockerUtils.getLabelScript(describable, script).run {
body.call()
}
} else {
return getLabelScript().run {
return DeclarativeDockerUtils.getLabelScript(describable, script).run {
configureRegistry(body).call()
}
}
}

protected DeclarativeAgentScript getLabelScript() {
String targetLabel = DeclarativeDockerUtils.getLabel(describable.label)
// TODO revert reflection in daad17b90ed0 when we can depend directly on pipeline-model-definition
def l = Jenkins.get().getDescriptorByName('org.jenkinsci.plugins.pipeline.modeldefinition.agent.impl.Label').instanceForName("label", [label: targetLabel])
l.copyFlags(describable)
l.customWorkspace = describable.customWorkspace
return (DeclarativeAgentScript) l.getScript(script)
}

protected Closure configureRegistry(Closure body) {
return {
DeclarativeDockerUtils.DockerRegistry registry = DeclarativeDockerUtils.DockerRegistry.build(describable.registryUrl, describable.registryCredentialsId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,13 @@

package org.jenkinsci.plugins.docker.workflow.declarative

import jenkins.model.Jenkins
import org.jenkinsci.plugins.pipeline.modeldefinition.SyntheticStageNames
import org.jenkinsci.plugins.pipeline.modeldefinition.Utils
import org.jenkinsci.plugins.workflow.cps.CpsScript
import org.jenkinsci.plugins.workflow.support.steps.build.RunWrapper

class DockerPipelineFromDockerfileScript extends AbstractDockerPipelineScript<DockerPipelineFromDockerfile> {

// TODO revert reflection in daad17b90ed0 when we can depend directly on pipeline-model-definition
static Class Utils = Jenkins.get().pluginManager.getPlugin('pipeline-model-definition').classLoader.loadClass('org.jenkinsci.plugins.pipeline.modeldefinition.Utils')

DockerPipelineFromDockerfileScript(CpsScript s, DockerPipelineFromDockerfile a) {
super(s, a)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,12 @@

package org.jenkinsci.plugins.docker.workflow.declarative

import jenkins.model.Jenkins
import org.jenkinsci.plugins.pipeline.modeldefinition.SyntheticStageNames
import org.jenkinsci.plugins.pipeline.modeldefinition.Utils
import org.jenkinsci.plugins.workflow.cps.CpsScript

class DockerPipelineScript extends AbstractDockerPipelineScript<DockerPipeline> {

// TODO revert reflection in daad17b90ed0 when we can depend directly on pipeline-model-definition
static Class Utils = Jenkins.get().pluginManager.getPlugin('pipeline-model-definition').classLoader.loadClass('org.jenkinsci.plugins.pipeline.modeldefinition.Utils')

DockerPipelineScript(CpsScript s, DockerPipeline a) {
super(s, a)
}
Expand Down
Loading