Skip to content

Commit 3186bed

Browse files
authored
Merge pull request #87 from rsandell/jcasc
Configuration as Code support
2 parents f5fcfdd + 01ed2ad commit 3186bed

File tree

7 files changed

+186
-46
lines changed

7 files changed

+186
-46
lines changed

pom.xml

Lines changed: 32 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>org.jenkins-ci.plugins</groupId>
77
<artifactId>plugin</artifactId>
8-
<version>3.43</version>
8+
<version>4.2</version>
99
<relativePath />
1010
</parent>
1111

@@ -34,11 +34,10 @@
3434
<properties>
3535
<revision>1.17</revision>
3636
<changelist>-SNAPSHOT</changelist>
37-
<jenkins.version>2.150.1</jenkins.version>
37+
<jenkins.version>2.222.4</jenkins.version>
3838
<java.level>8</java.level>
39-
<workflow-step-api.version>2.19</workflow-step-api.version>
40-
<workflow-cps.version>2.67</workflow-cps.version>
41-
<workflow-support.version>3.3</workflow-support.version>
39+
<pipeline-model-definition-version>1.3.8</pipeline-model-definition-version>
40+
<jcasc.version>1.41</jcasc.version>
4241
</properties>
4342

4443
<repositories>
@@ -59,12 +58,10 @@
5958
<dependency>
6059
<groupId>org.jenkins-ci.plugins</groupId>
6160
<artifactId>credentials</artifactId>
62-
<version>2.1.18</version>
6361
</dependency>
6462
<dependency>
6563
<groupId>org.jenkins-ci.plugins</groupId>
6664
<artifactId>credentials-binding</artifactId>
67-
<version>1.18</version>
6865
</dependency>
6966
<dependency>
7067
<groupId>org.jenkins-ci.plugins</groupId>
@@ -74,7 +71,7 @@
7471
<dependency>
7572
<groupId>org.jenkinsci.plugins</groupId>
7673
<artifactId>pipeline-model-extensions</artifactId>
77-
<version>1.3.8</version>
74+
<version>${pipeline-model-definition-version}</version>
7875
<!-- optional because the dependency subtree is quite large -->
7976
<optional>true</optional>
8077
</dependency>
@@ -84,115 +81,107 @@
8481
<artifactId>multiline-secrets-ui</artifactId>
8582
<version>1.0</version>
8683
</dependency>
87-
88-
<!-- for Pipeline-based unit tests -->
8984
<dependency>
9085
<groupId>org.jenkins-ci.plugins</groupId>
91-
<artifactId>scm-api</artifactId>
92-
<version>2.4.1</version>
93-
<scope>test</scope>
86+
<artifactId>structs</artifactId>
9487
</dependency>
88+
89+
<!-- for Pipeline-based unit tests -->
9590
<dependency>
9691
<groupId>org.jenkins-ci.plugins</groupId>
97-
<artifactId>structs</artifactId>
98-
<version>1.18</version>
92+
<artifactId>scm-api</artifactId>
9993
<scope>test</scope>
10094
</dependency>
10195
<dependency>
10296
<groupId>org.jenkins-ci.plugins.workflow</groupId>
10397
<artifactId>workflow-api</artifactId>
104-
<version>2.33</version>
10598
<scope>test</scope>
10699
</dependency>
107100
<dependency>
108101
<groupId>org.jenkins-ci.plugins.workflow</groupId>
109102
<artifactId>workflow-step-api</artifactId>
110-
<version>${workflow-step-api.version}</version>
111103
<scope>test</scope>
112104
</dependency>
113105
<dependency>
114106
<groupId>org.jenkins-ci.plugins.workflow</groupId>
115107
<artifactId>workflow-step-api</artifactId>
116-
<version>${workflow-step-api.version}</version>
117108
<classifier>tests</classifier>
118109
<scope>test</scope>
119110
</dependency>
120111
<dependency>
121112
<groupId>org.jenkins-ci.plugins.workflow</groupId>
122113
<artifactId>workflow-cps</artifactId>
123-
<version>${workflow-cps.version}</version>
124114
<scope>test</scope>
125115
</dependency>
126116
<dependency>
127117
<groupId>org.jenkins-ci.plugins.workflow</groupId>
128118
<artifactId>workflow-cps</artifactId>
129-
<version>${workflow-cps.version}</version>
130119
<classifier>tests</classifier>
131120
<scope>test</scope>
132121
</dependency>
133122
<dependency>
134123
<groupId>org.jenkins-ci.plugins.workflow</groupId>
135124
<artifactId>workflow-job</artifactId>
136-
<version>2.32</version>
137125
<scope>test</scope>
138126
</dependency>
139127
<dependency>
140128
<groupId>org.jenkins-ci.plugins.workflow</groupId>
141129
<artifactId>workflow-durable-task-step</artifactId>
142-
<version>2.30</version>
143130
<scope>test</scope>
144131
</dependency>
145132
<dependency>
146133
<groupId>org.jenkins-ci.plugins.workflow</groupId>
147134
<artifactId>workflow-basic-steps</artifactId>
148-
<version>2.15</version>
149135
<scope>test</scope>
150136
</dependency>
151137
<dependency>
152138
<groupId>org.jenkins-ci.plugins.workflow</groupId>
153139
<artifactId>workflow-support</artifactId>
154-
<version>${workflow-support.version}</version>
155140
<scope>test</scope>
156141
</dependency>
157142
<dependency>
158143
<groupId>org.jenkins-ci.plugins.workflow</groupId>
159144
<artifactId>workflow-support</artifactId>
160-
<version>${workflow-support.version}</version>
161145
<classifier>tests</classifier>
162146
<scope>test</scope>
163147
</dependency>
164148
<dependency>
165149
<groupId>org.jenkinsci.plugins</groupId>
166150
<artifactId>pipeline-model-definition</artifactId>
167-
<version>1.3.8</version>
168-
<scope>test</scope>
169-
</dependency>
170-
<!-- these dependencies are added to satisfy the enforcer rules -->
171-
<dependency>
172-
<groupId>org.apache.commons</groupId>
173-
<artifactId>commons-lang3</artifactId>
174-
<version>3.7</version>
151+
<version>${pipeline-model-definition-version}</version>
175152
<scope>test</scope>
176153
</dependency>
154+
<!-- Dependencies for testing JCasC compatibility-->
177155
<dependency>
178-
<groupId>org.jenkins-ci.plugins</groupId>
179-
<artifactId>mailer</artifactId>
180-
<version>1.20</version>
156+
<groupId>io.jenkins</groupId>
157+
<artifactId>configuration-as-code</artifactId>
158+
<version>${jcasc.version}</version>
181159
<scope>test</scope>
182160
</dependency>
183161
<dependency>
184-
<groupId>org.jenkins-ci.plugins</groupId>
185-
<artifactId>ssh-credentials</artifactId>
186-
<version>1.13</version>
162+
<groupId>io.jenkins.configuration-as-code</groupId>
163+
<artifactId>test-harness</artifactId>
164+
<version>${jcasc.version}</version>
187165
<scope>test</scope>
188166
</dependency>
167+
<!-- these dependencies are added to satisfy the enforcer rules -->
189168
<dependency>
190-
<groupId>org.jenkins-ci.plugins.workflow</groupId>
191-
<artifactId>workflow-scm-step</artifactId>
192-
<version>2.6</version>
169+
<groupId>org.apache.commons</groupId>
170+
<artifactId>commons-lang3</artifactId>
171+
<version>3.9</version>
193172
<scope>test</scope>
194173
</dependency>
195-
196174
</dependencies>
175+
<dependencyManagement>
176+
<dependencies>
177+
<dependency>
178+
<groupId>io.jenkins.tools.bom</groupId>
179+
<artifactId>bom-2.222.x</artifactId>
180+
<version>11</version>
181+
<scope>import</scope>
182+
<type>pom</type>
183+
</dependency>
184+
</dependencies>
185+
</dependencyManagement>
197186

198187
</project>

src/main/java/org/jenkinsci/plugins/docker/commons/credentials/DockerServerCredentials.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import hudson.Extension;
2929
import hudson.Util;
3030
import hudson.util.Secret;
31+
import org.jenkinsci.Symbol;
3132
import org.kohsuke.stapler.DataBoundConstructor;
3233

3334
import javax.annotation.CheckForNull;
@@ -111,7 +112,7 @@ public String getServerCaCertificate() {
111112
return serverCaCertificate;
112113
}
113114

114-
@Extension
115+
@Extension @Symbol({"x509ClientCert", "dockerServer"})
115116
public static class DescriptorImpl extends BaseStandardCredentialsDescriptor {
116117
@Override
117118
public String getDisplayName() {

src/main/java/org/jenkinsci/plugins/docker/commons/tools/DockerTool.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import javax.annotation.Nonnull;
4444
import javax.annotation.Nullable;
4545
import jenkins.model.Jenkins;
46+
import org.jenkinsci.Symbol;
4647
import org.kohsuke.stapler.DataBoundConstructor;
4748

4849
/**
@@ -114,7 +115,8 @@ public DockerTool forNode(Node node, TaskListener log) throws IOException, Inter
114115
}
115116
}
116117

117-
@Extension public static class DescriptorImpl extends ToolDescriptor<DockerTool> {
118+
@Extension @Symbol("dockerTool")
119+
public static class DescriptorImpl extends ToolDescriptor<DockerTool> {
118120

119121
@Override public String getDisplayName() {
120122
return "Docker";

src/main/java/org/jenkinsci/plugins/docker/commons/tools/DockerToolInstaller.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import java.util.regex.Pattern;
4545
import javax.annotation.Nonnull;
4646
import jenkins.security.MasterToSlaveCallable;
47+
import org.jenkinsci.Symbol;
4748
import org.kohsuke.stapler.DataBoundConstructor;
4849

4950
/**
@@ -165,7 +166,7 @@ private static VersionNumber parseVersion(String version) {
165166
throw new IllegalArgumentException("Failed to parse version " + version);
166167
}
167168

168-
@Extension
169+
@Extension @Symbol("fromDocker")
169170
public static class DescriptorImpl extends ToolInstallerDescriptor<DockerToolInstaller> {
170171

171172
@Override
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
package org.jenkinsci.plugins.docker.commons;
2+
3+
import com.cloudbees.plugins.credentials.CredentialsMatchers;
4+
import com.cloudbees.plugins.credentials.CredentialsProvider;
5+
import com.cloudbees.plugins.credentials.common.IdCredentials;
6+
import hudson.security.ACL;
7+
import hudson.tools.InstallSourceProperty;
8+
import hudson.tools.ToolProperty;
9+
import hudson.tools.ToolPropertyDescriptor;
10+
import hudson.util.DescribableList;
11+
import hudson.util.Secret;
12+
import io.jenkins.plugins.casc.misc.RoundTripAbstractTest;
13+
import org.jenkinsci.plugins.docker.commons.credentials.DockerServerCredentials;
14+
import org.jenkinsci.plugins.docker.commons.credentials.DockerServerDomainRequirement;
15+
import org.jenkinsci.plugins.docker.commons.tools.DockerTool;
16+
import org.jenkinsci.plugins.docker.commons.tools.DockerToolInstaller;
17+
import org.junit.runner.RunWith;
18+
import org.junit.runners.Parameterized;
19+
import org.jvnet.hudson.test.RestartableJenkinsRule;
20+
21+
import static org.hamcrest.MatcherAssert.assertThat;
22+
import static org.hamcrest.beans.HasPropertyWithValue.hasProperty;
23+
import static org.hamcrest.collection.ArrayMatching.arrayContaining;
24+
import static org.hamcrest.collection.IsArrayWithSize.arrayWithSize;
25+
import static org.hamcrest.collection.IsIterableContainingInOrder.contains;
26+
import static org.hamcrest.core.AllOf.allOf;
27+
import static org.hamcrest.core.IsEqual.equalTo;
28+
import static org.hamcrest.core.IsInstanceOf.instanceOf;
29+
import static org.hamcrest.core.IsNull.nullValue;
30+
import static org.junit.Assert.assertEquals;
31+
import static org.junit.Assert.assertNotNull;
32+
33+
@RunWith(Parameterized.class)
34+
public class CasCTest extends RoundTripAbstractTest {
35+
36+
final String resource;
37+
38+
public CasCTest(final String resource) {
39+
this.resource = resource;
40+
}
41+
42+
@Parameterized.Parameters(name = "{0}")
43+
public static Object[][] params() {
44+
return new Object[][]{{"casc_bare.yaml"}, {"casc_symbols.yaml"}};
45+
}
46+
47+
@Override
48+
protected void assertConfiguredAsExpected(final RestartableJenkinsRule j, final String s) {
49+
50+
//The credentials
51+
final IdCredentials cred = CredentialsMatchers.firstOrNull(CredentialsProvider.lookupCredentials(IdCredentials.class, j.j.jenkins,
52+
ACL.SYSTEM, new DockerServerDomainRequirement()), CredentialsMatchers.withId("dockerx509"));
53+
assertNotNull(cred);
54+
assertThat(cred, instanceOf(DockerServerCredentials.class));
55+
DockerServerCredentials dCreds = (DockerServerCredentials) cred;
56+
assertEquals("THE CLIENT", dCreds.getClientCertificate());
57+
assertEquals("THE SERVER", dCreds.getServerCaCertificate());
58+
assertEquals("Be wewy wewy cuwiet", Secret.toString(dCreds.getClientKeySecret()));
59+
assertEquals("Docker X.509", dCreds.getDescription());
60+
61+
62+
//The ToolInstaller
63+
final DockerTool[] installations = j.j.jenkins.getDescriptorByType(DockerTool.DescriptorImpl.class).getInstallations();
64+
assertNotNull(installations);
65+
assertThat(installations, arrayWithSize(2));
66+
assertThat(installations, arrayContaining(
67+
allOf(
68+
hasProperty("name", equalTo("docker-latest")),
69+
hasProperty("home", nullValue())
70+
),
71+
allOf(
72+
hasProperty("name", equalTo("docker-native")),
73+
hasProperty("home", equalTo("/etc/docket/docker"))
74+
)
75+
));
76+
final DescribableList<ToolProperty<?>, ToolPropertyDescriptor> properties = installations[0].getProperties();
77+
assertThat(properties, contains(instanceOf(InstallSourceProperty.class)));
78+
final InstallSourceProperty property = (InstallSourceProperty) properties.get(0);
79+
assertThat(property.installers, contains(
80+
allOf(
81+
instanceOf(DockerToolInstaller.class),
82+
hasProperty("version", equalTo("latest"))
83+
)
84+
));
85+
86+
/*
87+
* DockerRegistryEndpoint is not directly used in this plugin in any global config sense,
88+
* So it is better tested in the plugins that uses it for example docker workflow plugin:
89+
* https://github.com/jenkinsci/docker-workflow-plugin/blob/2ba1ac97b75a3f188e243333b31ef06d55b9221a/src/main/java/org/jenkinsci/plugins/docker/workflow/declarative/GlobalConfig.java
90+
*/
91+
92+
}
93+
94+
@Override
95+
protected String configResource() {
96+
return resource;
97+
}
98+
99+
@Override
100+
protected String stringInLogExpected() {
101+
return DockerServerCredentials.class.getName();
102+
}
103+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
credentials:
2+
system:
3+
domainCredentials:
4+
- credentials:
5+
- dockerServer:
6+
clientCertificate: "THE CLIENT"
7+
clientKeySecret: "Be wewy wewy cuwiet"
8+
description: "Docker X.509"
9+
id: "dockerx509"
10+
scope: GLOBAL
11+
serverCaCertificate: "THE SERVER"
12+
tool:
13+
dockerTool:
14+
installations:
15+
- name: "docker-latest"
16+
properties:
17+
- installSource:
18+
installers:
19+
- docker:
20+
version: "latest"
21+
- home: "/etc/docket/docker"
22+
name: "docker-native"
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
credentials:
2+
system:
3+
domainCredentials:
4+
- credentials:
5+
- x509ClientCert:
6+
clientCertificate: "THE CLIENT"
7+
clientKeySecret: "Be wewy wewy cuwiet"
8+
description: "Docker X.509"
9+
id: "dockerx509"
10+
scope: GLOBAL
11+
serverCaCertificate: "THE SERVER"
12+
tool:
13+
dockerTool:
14+
installations:
15+
- name: "docker-latest"
16+
properties:
17+
- installSource:
18+
installers:
19+
- fromDocker:
20+
version: "latest"
21+
- home: "/etc/docket/docker"
22+
name: "docker-native"

0 commit comments

Comments
 (0)