Skip to content

Commit a3978f9

Browse files
authored
Merge pull request #37 from jglick/Jenkinsfile
Added a Jenkinsfile
2 parents 8e3f297 + 4a42848 commit a3978f9

6 files changed

Lines changed: 35 additions & 24 deletions

File tree

Jenkinsfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
buildPlugin(jenkinsVersions: [null, '2.32.3'])

pom.xml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,13 @@
6363
</pluginRepositories>
6464
<properties>
6565
<jenkins.version>1.642.3</jenkins.version>
66+
<workflow-step-api-plugin.version>2.9</workflow-step-api-plugin.version>
6667
</properties>
6768
<dependencies>
6869
<dependency>
6970
<groupId>org.jenkins-ci.plugins.workflow</groupId>
7071
<artifactId>workflow-step-api</artifactId>
71-
<version>2.9</version>
72+
<version>${workflow-step-api-plugin.version}</version>
7273
</dependency>
7374
<dependency>
7475
<groupId>org.jenkins-ci.plugins</groupId>
@@ -78,7 +79,7 @@
7879
<dependency>
7980
<groupId>org.jenkins-ci.plugins.workflow</groupId>
8081
<artifactId>workflow-step-api</artifactId>
81-
<version>2.9</version>
82+
<version>${workflow-step-api-plugin.version}</version>
8283
<classifier>tests</classifier>
8384
<scope>test</scope>
8485
</dependency>
@@ -154,5 +155,11 @@
154155
<version>2.0</version>
155156
<scope>test</scope>
156157
</dependency>
158+
<dependency>
159+
<groupId>org.jenkins-ci.plugins.workflow</groupId>
160+
<artifactId>workflow-scm-step</artifactId>
161+
<version>2.2</version>
162+
<scope>test</scope>
163+
</dependency>
157164
</dependencies>
158165
</project>

src/main/java/org/jenkinsci/plugins/workflow/steps/CoreStep.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,7 @@ public Collection<? extends Descriptor<?>> getApplicableDescriptors() {
111111
return r;
112112
}
113113
private <T extends Describable<T>,D extends Descriptor<T>> void populate(List<Descriptor<?>> r, Class<T> c) {
114-
Jenkins j = Jenkins.getInstance();
115-
if (j == null) {
116-
return;
117-
}
118-
for (Descriptor<?> d : j.getDescriptorList(c)) {
114+
for (Descriptor<?> d : Jenkins.getActiveInstance().getDescriptorList(c)) {
119115
if (SimpleBuildStep.class.isAssignableFrom(d.clazz)) {
120116
r.add(d);
121117
}

src/test/java/org/jenkinsci/plugins/workflow/steps/EnvStepRunTest.java

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
package org.jenkinsci.plugins.workflow.steps;
2626

27+
import hudson.Functions;
2728
import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition;
2829
import org.jenkinsci.plugins.workflow.job.WorkflowJob;
2930
import org.jenkinsci.plugins.workflow.job.WorkflowRun;
@@ -46,19 +47,19 @@ public class EnvStepRunTest {
4647
WorkflowJob p = story.j.jenkins.createProject(WorkflowJob.class, "p");
4748
p.setDefinition(new CpsFlowDefinition(
4849
"env.CUSTOM = 'initial'\n" +
49-
"env.FOOPATH = '/opt/foos'\n" +
50+
"env.FOOPATH = node {isUnix() ? '/opt/foos' : 'C:\\\\foos'}\n" +
5051
"env.NULLED = 'outside'\n" +
5152
"node {\n" +
52-
" withEnv(['CUSTOM=override', 'NOVEL=val', 'BUILD_TAG=custom', 'NULLED=', 'FOOPATH+BALL=/opt/ball']) {\n" +
53-
" sh 'echo inside CUSTOM=$CUSTOM NOVEL=$NOVEL BUILD_TAG=$BUILD_TAG NULLED=$NULLED FOOPATH=$FOOPATH:'\n" +
53+
" withEnv(['CUSTOM=override', 'NOVEL=val', 'BUILD_TAG=custom', 'NULLED=', isUnix() ? 'FOOPATH+BALL=/opt/ball' : 'FOOPATH+BALL=C:\\\\ball']) {\n" +
54+
" isUnix() ? sh('echo inside CUSTOM=$CUSTOM NOVEL=$NOVEL BUILD_TAG=$BUILD_TAG NULLED=$NULLED FOOPATH=$FOOPATH:') : bat('echo inside CUSTOM=%CUSTOM% NOVEL=%NOVEL% BUILD_TAG=%BUILD_TAG% NULLED=%NULLED% FOOPATH=%FOOPATH%;')\n" +
5455
" echo \"groovy NULLED=${env.NULLED}\"\n" +
5556
" }\n" +
56-
" sh 'echo outside CUSTOM=$CUSTOM NOVEL=$NOVEL NULLED=outside:'\n" +
57-
"}"));
57+
" isUnix() ? sh('echo outside CUSTOM=$CUSTOM NOVEL=$NOVEL NULLED=outside') : bat('echo outside CUSTOM=%CUSTOM% NOVEL=%NOVEL% NULLED=outside')\n" +
58+
"}", true));
5859
WorkflowRun b = story.j.assertBuildStatusSuccess(p.scheduleBuild2(0));
59-
story.j.assertLogContains("inside CUSTOM=override NOVEL=val BUILD_TAG=custom NULLED= FOOPATH=/opt/ball:/opt/foos:", b);
60+
story.j.assertLogContains(Functions.isWindows() ? "inside CUSTOM=override NOVEL=val BUILD_TAG=custom NULLED= FOOPATH=C:\\ball;C:\\foos;" : "inside CUSTOM=override NOVEL=val BUILD_TAG=custom NULLED= FOOPATH=/opt/ball:/opt/foos:", b);
6061
story.j.assertLogContains("groovy NULLED=null", b);
61-
story.j.assertLogContains("outside CUSTOM=initial NOVEL= NULLED=outside:", b);
62+
story.j.assertLogContains("outside CUSTOM=initial NOVEL= NULLED=outside", b);
6263
}
6364
});
6465
}
@@ -69,10 +70,10 @@ public class EnvStepRunTest {
6970
WorkflowJob p = story.j.jenkins.createProject(WorkflowJob.class, "p");
7071
p.setDefinition(new CpsFlowDefinition(
7172
"parallel a: {\n" +
72-
" node {withEnv(['TOOL=aloc']) {semaphore 'a'; sh 'echo TOOL=$TOOL'}}\n" +
73+
" node {withEnv(['TOOL=aloc']) {semaphore 'a'; isUnix() ? sh('echo TOOL=$TOOL') : bat('echo TOOL=%TOOL%')}}\n" +
7374
"}, b: {\n" +
74-
" node {withEnv(['TOOL=bloc']) {semaphore 'b'; sh 'echo TOOL=$TOOL'}}\n" +
75-
"}"));
75+
" node {withEnv(['TOOL=bloc']) {semaphore 'b'; isUnix() ? sh('echo TOOL=$TOOL') : bat('echo TOOL=%TOOL%')}}\n" +
76+
"}", true));
7677
WorkflowRun b = p.scheduleBuild2(0).getStartCondition().get();
7778
SemaphoreStep.waitForStart("a/1", b);
7879
SemaphoreStep.waitForStart("b/1", b);
@@ -92,7 +93,7 @@ public class EnvStepRunTest {
9293
p.setDefinition(new CpsFlowDefinition(
9394
"def show(which) {\n" +
9495
" echo \"groovy ${which} ${env.TESTVAR}:\"\n" +
95-
" sh \"echo shell ${which} \\$TESTVAR:\"\n" +
96+
" isUnix() ? sh(\"echo shell ${which} \\$TESTVAR:\") : bat(\"echo shell ${which} %TESTVAR%:\")\n" +
9697
"}\n" +
9798
"node {\n" +
9899
" withEnv(['TESTVAR=val']) {\n" +
@@ -101,7 +102,7 @@ public class EnvStepRunTest {
101102
" show 'after'\n" +
102103
" }\n" +
103104
" show 'outside'\n" +
104-
"}"));
105+
"}", true));
105106
WorkflowRun b = p.scheduleBuild2(0).getStartCondition().get();
106107
SemaphoreStep.waitForStart("restarting/1", b);
107108
}
@@ -128,7 +129,7 @@ public class EnvStepRunTest {
128129
"node {\n" +
129130
" withEnv(['A=one']) {\n" +
130131
" withEnv(['B=two']) {\n" +
131-
" sh 'echo A=$A B=$B'\n" +
132+
" isUnix() ? sh('echo A=$A B=$B') : bat('echo A=%A% B=%B%')\n" +
132133
" }\n" +
133134
" }\n" +
134135
"}"));

src/test/java/org/jenkinsci/plugins/workflow/steps/ToolStepRunTest.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
import java.io.File;
4747
import java.util.List;
4848
import java.util.Set;
49+
import org.jenkinsci.plugins.scriptsecurity.scripts.ScriptApproval;
4950

5051
public class ToolStepRunTest {
5152

@@ -69,10 +70,11 @@ public class ToolStepRunTest {
6970
}
7071

7172
WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p");
72-
p.setDefinition(new CpsFlowDefinition("node {def home = tool name: '" + name + "', type: '" + type + "'; sh \"M2_HOME=${home} ${home}/bin/mvn -version\"}",
73+
ScriptApproval.get().approveSignature("staticMethod org.codehaus.groovy.runtime.DefaultGroovyMethods split java.lang.String"); // TODO pending https://github.com/jenkinsci/script-security-plugin/pull/113
74+
p.setDefinition(new CpsFlowDefinition("node {def home = tool name: '" + name + "', type: '" + type + "'; def settings = readFile($/$home/conf/settings.xml/$).split(); echo settings[-1]}",
7375
true));
7476

75-
r.assertLogContains("Apache Maven 3", r.assertBuildStatusSuccess(p.scheduleBuild2(0)));
77+
r.assertLogContains("</settings>", r.assertBuildStatusSuccess(p.scheduleBuild2(0)));
7678
}
7779

7880
@Test public void toolWithSymbol() throws Exception {

src/test/java/org/jenkinsci/plugins/workflow/steps/ToolStepTest.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
package org.jenkinsci.plugins.workflow.steps;
2626

2727
import hudson.model.JDK;
28+
import org.jenkinsci.plugins.structs.SymbolLookup;
2829
import org.junit.Test;
2930
import static org.junit.Assert.*;
3031
import org.junit.Rule;
@@ -36,15 +37,18 @@ public class ToolStepTest {
3637

3738
@Test public void configRoundTrip() throws Exception {
3839
String name = "My JDK";
39-
String type = r.jenkins.getDescriptorByType(JDK.DescriptorImpl.class).getId();
40+
JDK.DescriptorImpl desc = r.jenkins.getDescriptorByType(JDK.DescriptorImpl.class);
41+
String type = desc.getId();
4042
r.jenkins.getJDKs().add(new JDK(name, "/wherever"));
4143
ToolStep s = new StepConfigTester(r).configRoundTrip(new ToolStep(name));
4244
assertEquals(name, s.getName());
4345
assertEquals(null, s.getType());
4446
s.setType(type);
4547
s = new StepConfigTester(r).configRoundTrip(s);
4648
assertEquals(name, s.getName());
47-
assertEquals(type, s.getType());
49+
if (SymbolLookup.getSymbolValue(desc).isEmpty()) {
50+
assertEquals(type, s.getType());
51+
} // else (Jenkins 2.x) StepConfigTester does not make sense since in real life we would not read an existing value (an ID) into a pulldown listing only symbols
4852
}
4953

5054
}

0 commit comments

Comments
 (0)