Skip to content
This repository was archived by the owner on Mar 27, 2025. It is now read-only.

Commit c066472

Browse files
authored
Merge pull request #114 from mathworks/DSL-qual-branch-new
Dsl qual branch new
2 parents 2c46140 + c4acc2b commit c066472

25 files changed

+989
-13
lines changed

pom.xml

Lines changed: 52 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<parent>
55
<groupId>org.jenkins-ci.plugins</groupId>
66
<artifactId>plugin</artifactId>
7-
<version>3.4</version>
7+
<version>3.57</version>
88
<relativePath />
99
</parent>
1010
<artifactId>matlab</artifactId>
@@ -20,7 +20,7 @@
2020
</developers>
2121

2222
<properties>
23-
<jenkins.version>2.7.3</jenkins.version>
23+
<jenkins.version>2.164.3</jenkins.version>
2424
<java.level>8</java.level>
2525
</properties>
2626

@@ -52,14 +52,57 @@
5252
<url>http://github.com/jenkinsci/matlab-plugin</url>
5353
<tag>HEAD</tag>
5454
</scm>
55-
55+
<dependencyManagement>
56+
<dependencies>
57+
<dependency>
58+
<groupId>io.jenkins.tools.bom</groupId>
59+
<artifactId>bom-2.164.x</artifactId>
60+
<version>4</version>
61+
<scope>import</scope>
62+
<type>pom</type>
63+
</dependency>
64+
</dependencies>
65+
</dependencyManagement>
5666
<dependencies>
57-
<!-- https://mvnrepository.com/artifact/org.jenkins-ci.plugins/matrix-project -->
58-
<dependency>
59-
<groupId>org.jenkins-ci.plugins</groupId>
60-
<artifactId>matrix-project</artifactId>
61-
<version>1.14</version>
62-
</dependency>
67+
68+
<!-- Pipeline Step dependencies -->
69+
70+
<dependency>
71+
<groupId>org.jenkins-ci.plugins</groupId>
72+
<artifactId>matrix-project</artifactId>
73+
</dependency>
74+
75+
<dependency>
76+
<groupId>org.jenkins-ci.plugins.workflow</groupId>
77+
<artifactId>workflow-step-api</artifactId>
78+
</dependency>
79+
<dependency>
80+
<groupId>org.jenkins-ci.plugins.workflow</groupId>
81+
<artifactId>workflow-api</artifactId>
82+
</dependency>
83+
84+
<!-- Jenkins workflow test dependencies -->
85+
86+
<dependency>
87+
<groupId>org.jenkins-ci.plugins.workflow</groupId>
88+
<artifactId>workflow-basic-steps</artifactId>
89+
<scope>test</scope>
90+
</dependency>
91+
<dependency>
92+
<groupId>org.jenkins-ci.plugins.workflow</groupId>
93+
<artifactId>workflow-cps</artifactId>
94+
<scope>test</scope>
95+
</dependency>
96+
<dependency>
97+
<groupId>org.jenkins-ci.plugins.workflow</groupId>
98+
<artifactId>workflow-durable-task-step</artifactId>
99+
<scope>test</scope>
100+
</dependency>
101+
<dependency>
102+
<groupId>org.jenkins-ci.plugins.workflow</groupId>
103+
<artifactId>workflow-job</artifactId>
104+
<scope>test</scope>
105+
</dependency>
63106
</dependencies>
64107

65108
<build>
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
package com.mathworks.ci;
2+
3+
import java.io.IOException;
4+
import org.jenkinsci.plugins.workflow.steps.StepContext;
5+
import org.jenkinsci.plugins.workflow.steps.StepExecution;
6+
import hudson.EnvVars;
7+
import hudson.FilePath;
8+
import hudson.Launcher;
9+
import hudson.Launcher.ProcStarter;
10+
import hudson.model.Result;
11+
import hudson.model.TaskListener;
12+
13+
public class MatlabCommandStepExecution extends StepExecution implements MatlabBuild {
14+
15+
private static final long serialVersionUID = 1957239693658914450L;
16+
17+
private String command;
18+
private EnvVars env;
19+
20+
21+
public MatlabCommandStepExecution(StepContext context, String command) {
22+
super(context);
23+
this.command = command;
24+
}
25+
26+
private String getCommand() {
27+
return this.env == null ? this.command : this.env.expand(this.command );
28+
}
29+
30+
private void setEnv(EnvVars env) {
31+
this.env = env;
32+
}
33+
34+
@Override
35+
public boolean start() throws Exception {
36+
final Launcher launcher = getContext().get(Launcher.class);
37+
final FilePath workspace = getContext().get(FilePath.class);
38+
final TaskListener listener = getContext().get(TaskListener.class);
39+
final EnvVars env = getContext().get(EnvVars.class);
40+
setEnv(env);
41+
42+
//Make sure the Workspace exists before run
43+
44+
workspace.mkdirs();
45+
46+
int res = execMatlabCommand(workspace, launcher, listener, env);
47+
48+
getContext().setResult((res == 0) ? Result.SUCCESS : Result.FAILURE);
49+
50+
getContext().onSuccess(true);
51+
52+
//return false represents the asynchronous run.
53+
return false;
54+
}
55+
56+
@Override
57+
public void stop(Throwable cause) throws Exception {
58+
getContext().onFailure(cause);
59+
}
60+
61+
private synchronized int execMatlabCommand(FilePath workspace, Launcher launcher,
62+
TaskListener listener, EnvVars envVars) throws IOException, InterruptedException {
63+
final String uniqueTmpFldrName = getUniqueNameForRunnerFile();
64+
final String uniqueCommandFile =
65+
"command_" + getUniqueNameForRunnerFile().replaceAll("-", "_");
66+
final FilePath uniqeTmpFolderPath =
67+
getFilePathForUniqueFolder(launcher, uniqueTmpFldrName, workspace);
68+
69+
// Create MATLAB script
70+
createMatlabScriptByName(uniqeTmpFolderPath, uniqueCommandFile, workspace, listener);
71+
ProcStarter matlabLauncher;
72+
73+
try {
74+
matlabLauncher = getProcessToRunMatlabCommand(workspace, launcher, listener, envVars,
75+
uniqueCommandFile, uniqueTmpFldrName);
76+
launcher.launch().pwd(uniqeTmpFolderPath).envs(envVars);
77+
listener.getLogger()
78+
.println("#################### Starting command output ####################");
79+
return matlabLauncher.pwd(uniqeTmpFolderPath).join();
80+
81+
} catch (Exception e) {
82+
listener.getLogger().println(e.getMessage());
83+
return 1;
84+
} finally {
85+
// Cleanup the tmp directory
86+
if (uniqeTmpFolderPath.exists()) {
87+
uniqeTmpFolderPath.deleteRecursive();
88+
}
89+
}
90+
}
91+
92+
private void createMatlabScriptByName(FilePath uniqeTmpFolderPath, String uniqueScriptName, FilePath workspace, TaskListener listener) throws IOException, InterruptedException {
93+
94+
// Create a new command runner script in the temp folder.
95+
final FilePath matlabCommandFile =
96+
new FilePath(uniqeTmpFolderPath, uniqueScriptName + ".m");
97+
final String matlabCommandFileContent =
98+
"cd '" + workspace.getRemote().replaceAll("'", "''") + "';\n" + getCommand();
99+
100+
// Display the commands on console output for users reference
101+
listener.getLogger()
102+
.println("Generating MATLAB script with content:\n" + getCommand() + "\n");
103+
104+
matlabCommandFile.write(matlabCommandFileContent, "UTF-8");
105+
}
106+
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
package com.mathworks.ci;
2+
3+
/**
4+
* Copyright 2020 The MathWorks, Inc.
5+
*
6+
*/
7+
8+
import java.io.IOException;
9+
import org.jenkinsci.plugins.workflow.steps.StepContext;
10+
import org.jenkinsci.plugins.workflow.steps.StepExecution;
11+
import hudson.EnvVars;
12+
import hudson.FilePath;
13+
import hudson.Launcher;
14+
import hudson.Launcher.ProcStarter;
15+
import hudson.model.Result;
16+
import hudson.model.TaskListener;
17+
18+
public class MatlabRunTestsStepExecution extends StepExecution implements MatlabBuild {
19+
20+
private static final long serialVersionUID = 6704588180717665100L;
21+
22+
private String command;
23+
24+
25+
public MatlabRunTestsStepExecution(StepContext context, String command) {
26+
super(context);
27+
this.command = command;
28+
}
29+
30+
private String getCommand() {
31+
return this.command;
32+
}
33+
34+
@Override
35+
public boolean start() throws Exception {
36+
final Launcher launcher = getContext().get(Launcher.class);
37+
final FilePath workspace = getContext().get(FilePath.class);
38+
final TaskListener listener = getContext().get(TaskListener.class);
39+
final EnvVars env = getContext().get(EnvVars.class);
40+
41+
//Make sure the Workspace exists before run
42+
43+
workspace.mkdirs();
44+
45+
int res = execMatlabCommand(workspace, launcher, listener, env);
46+
47+
getContext().setResult((res == 0) ? Result.SUCCESS : Result.FAILURE);
48+
49+
getContext().onSuccess(true);
50+
51+
//return false represents the asynchronous run.
52+
return false;
53+
}
54+
55+
@Override
56+
public void stop(Throwable cause) throws Exception {
57+
getContext().onFailure(cause);
58+
}
59+
60+
private synchronized int execMatlabCommand(FilePath workspace, Launcher launcher,
61+
TaskListener listener, EnvVars envVars) throws IOException, InterruptedException {
62+
final String uniqueTmpFldrName = getUniqueNameForRunnerFile();
63+
try {
64+
ProcStarter matlabLauncher = getProcessToRunMatlabCommand(workspace, launcher, listener, envVars,
65+
envVars.expand(getCommand()), uniqueTmpFldrName);
66+
67+
68+
return matlabLauncher.pwd(workspace).join();
69+
} catch (Exception e) {
70+
listener.getLogger().println(e.getMessage());
71+
return 1;
72+
} finally {
73+
// Cleanup the runner File from tmp directory
74+
final FilePath matlabRunnerScript =
75+
getFilePathForUniqueFolder(launcher, uniqueTmpFldrName, workspace);
76+
if (matlabRunnerScript.exists()) {
77+
matlabRunnerScript.deleteRecursive();
78+
}
79+
}
80+
81+
}
82+
}

src/main/java/com/mathworks/ci/RunMatlabCommandBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ private EnvVars getEnv() {
6161
return this.env;
6262
}
6363

64-
@Symbol("RunMatlabCommand")
64+
6565
@Extension
6666
public static class RunMatlabCommandDescriptor extends BuildStepDescriptor<Builder> {
6767

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package com.mathworks.ci;
2+
3+
/**
4+
* Copyright 2020 The MathWorks, Inc.
5+
*
6+
*/
7+
8+
import java.util.Set;
9+
import org.jenkinsci.plugins.workflow.steps.Step;
10+
import org.jenkinsci.plugins.workflow.steps.StepContext;
11+
import org.jenkinsci.plugins.workflow.steps.StepDescriptor;
12+
import org.jenkinsci.plugins.workflow.steps.StepExecution;
13+
import org.kohsuke.stapler.DataBoundConstructor;
14+
import com.google.common.collect.ImmutableSet;
15+
import hudson.EnvVars;
16+
import hudson.Extension;
17+
import hudson.FilePath;
18+
import hudson.Launcher;
19+
import hudson.model.Run;
20+
import hudson.model.TaskListener;
21+
22+
public class RunMatlabCommandStep extends Step {
23+
24+
25+
private String command;
26+
27+
@DataBoundConstructor
28+
public RunMatlabCommandStep(String command) {
29+
this.command = command;
30+
}
31+
32+
33+
public String getCommand() {
34+
return this.command;
35+
}
36+
37+
@Override
38+
public StepExecution start(StepContext context) throws Exception {
39+
return new MatlabCommandStepExecution(context, getCommand());
40+
}
41+
42+
@Extension
43+
public static class CommandStepDescriptor extends StepDescriptor {
44+
45+
@Override
46+
public Set<? extends Class<?>> getRequiredContext() {
47+
return ImmutableSet.of(TaskListener.class, FilePath.class, Launcher.class,
48+
EnvVars.class, Run.class);
49+
}
50+
51+
@Override
52+
public String getFunctionName() {
53+
return Message.getValue("matlab.command.build.step.name");
54+
}
55+
56+
@Override
57+
public String getDisplayName() {
58+
return Message.getValue("matlab.command.step.display.name");
59+
}
60+
}
61+
}
62+
63+

src/main/java/com/mathworks/ci/RunMatlabTestsBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ protected Object readResolve() {
185185
}
186186

187187

188-
@Symbol("RunMatlabTests")
188+
189189
@Extension
190190
public static class RunMatlabTestsDescriptor extends BuildStepDescriptor<Builder> {
191191

0 commit comments

Comments
 (0)