1
0

Добавление шага ringCommand

This commit is contained in:
Ivan Smirnov
2024-03-06 18:29:38 +03:00
parent 6ac28af8a0
commit d73b9a97c9
7 changed files with 56 additions and 18 deletions

View File

@@ -36,6 +36,8 @@ interface IStepExecutor {
def cmd(String script) def cmd(String script)
def ringCommand(String script)
void tool(String toolName) void tool(String toolName)
def withCredentials(List bindings, Closure body) def withCredentials(List bindings, Closure body)

View File

@@ -62,6 +62,11 @@ class StepExecutor implements IStepExecutor {
return steps.cmd(script, returnStatus, returnStdout) return steps.cmd(script, returnStatus, returnStdout)
} }
@Override
def ringCommand(String script) {
return steps.ringCommand(script)
}
@Override @Override
void tool(String toolName) { void tool(String toolName) {
steps.tool toolName steps.tool toolName

View File

@@ -34,7 +34,7 @@ class DesignerToEdtFormatTransformation implements Serializable {
def env = steps.env(); def env = steps.env();
String workspaceDir = FileUtils.getFilePath("$env.WORKSPACE/$WORKSPACE").getRemote() def workspaceDir = FileUtils.getFilePath("$env.WORKSPACE/$WORKSPACE")
def srcDir = config.srcDir def srcDir = config.srcDir
def configurationRoot = FileUtils.getFilePath("$env.WORKSPACE/$srcDir") def configurationRoot = FileUtils.getFilePath("$env.WORKSPACE/$srcDir")
def edtVersionForRing = EDT.ringModule(config) def edtVersionForRing = EDT.ringModule(config)
@@ -47,10 +47,7 @@ class DesignerToEdtFormatTransformation implements Serializable {
def ringOpts = [Constants.DEFAULT_RING_OPTS] def ringOpts = [Constants.DEFAULT_RING_OPTS]
steps.withEnv(ringOpts) { steps.withEnv(ringOpts) {
String ringMessage = steps.cmd(ringCommand, false, true) steps.ringCommand(ringCommand)
if (ringMessage.contains("error")) {
steps.error(ringMessage)
}
} }
steps.zip(WORKSPACE, WORKSPACE_ZIP) steps.zip(WORKSPACE, WORKSPACE_ZIP)

View File

@@ -0,0 +1,22 @@
package ru.pulsar.jenkins.library.steps
import ru.pulsar.jenkins.library.IStepExecutor
import ru.pulsar.jenkins.library.ioc.ContextRegistry
class RingCommand implements Serializable {
private String script;
RingCommand(String script) {
this.script = script
};
def run() {
IStepExecutor steps = ContextRegistry.getContext().getStepExecutor()
String ringMessage = steps.cmd(script, false, true)
if (ringMessage.contains("error")) {
steps.error(ringMessage)
}
}
}

View File

@@ -29,14 +29,17 @@ class CmdTest {
final String script = "echo hello"; final String script = "echo hello";
Cmd cmd = new Cmd(script); Cmd cmd = new Cmd(script);
when(steps.bat(anyString(), anyBoolean(), anyBoolean(), anyString())).thenReturn(0);
when(steps.sh(anyString(), anyBoolean(), anyBoolean(), anyString())).thenReturn(0);
// when // when
int run = cmd.run(); Object run = cmd.run();
// then // then
verify(steps).isUnix(); verify(steps).isUnix();
assertThat(steps).satisfiesAnyOf( assertThat(steps).satisfiesAnyOf(
steps -> verify(steps).bat(contains(script), eq(false), anyString()), steps -> verify(steps).bat(contains(script), eq(false), eq(false), anyString()),
steps -> verify(steps).sh(contains(script), eq(false), anyString()) steps -> verify(steps).sh(contains(script), eq(false), eq(false), anyString())
); );
assertThat(run).isEqualTo(0); assertThat(run).isEqualTo(0);
@@ -49,8 +52,8 @@ class CmdTest {
Cmd cmd = new Cmd(script); Cmd cmd = new Cmd(script);
String thrownText = "failed"; String thrownText = "failed";
when(steps.bat(anyString(), anyBoolean(), anyString())).thenThrow(new Error(thrownText)); when(steps.bat(anyString(), anyBoolean(), anyBoolean(), anyString())).thenThrow(new Error(thrownText));
when(steps.sh(anyString(), anyBoolean(), anyString())).thenThrow(new Error(thrownText)); when(steps.sh(anyString(), anyBoolean(), anyBoolean(), anyString())).thenThrow(new Error(thrownText));
// when // when
Throwable thrown = catchThrowable(cmd::run); Throwable thrown = catchThrowable(cmd::run);
@@ -59,8 +62,8 @@ class CmdTest {
// then // then
verify(steps).isUnix(); verify(steps).isUnix();
assertThat(steps).satisfiesAnyOf( assertThat(steps).satisfiesAnyOf(
steps -> verify(steps).bat(contains(script), eq(false), anyString()), steps -> verify(steps).bat(contains(script), eq(false), eq(false), anyString()),
steps -> verify(steps).sh(contains(script), eq(false), anyString()) steps -> verify(steps).sh(contains(script), eq(false), eq(false), anyString())
); );
} }
@@ -70,17 +73,17 @@ class CmdTest {
final String script = "false"; final String script = "false";
Cmd cmd = new Cmd(script, true); Cmd cmd = new Cmd(script, true);
when(steps.bat(anyString(), anyBoolean(), anyString())).thenReturn(1); when(steps.bat(anyString(), anyBoolean(), anyBoolean(), anyString())).thenReturn(1);
when(steps.sh(anyString(), anyBoolean(), anyString())).thenReturn(1); when(steps.sh(anyString(), anyBoolean(), anyBoolean(), anyString())).thenReturn(1);
// when // when
int run = cmd.run(); Object run = cmd.run();
// then // then
verify(steps).isUnix(); verify(steps).isUnix();
assertThat(steps).satisfiesAnyOf( assertThat(steps).satisfiesAnyOf(
steps -> verify(steps).bat(contains(script), eq(true), anyString()), steps -> verify(steps).bat(contains(script), eq(true), eq(false), anyString()),
steps -> verify(steps).sh(contains(script), eq(true), anyString()) steps -> verify(steps).sh(contains(script), eq(true), eq(false), anyString())
); );
assertThat(run).isEqualTo(1); assertThat(run).isEqualTo(1);

View File

@@ -1,7 +1,7 @@
import ru.pulsar.jenkins.library.steps.Cmd import ru.pulsar.jenkins.library.steps.Cmd
import ru.pulsar.jenkins.library.ioc.ContextRegistry import ru.pulsar.jenkins.library.ioc.ContextRegistry
int call(String script, boolean returnStatus = false, boolean returnStdout = false ) { def call(String script, boolean returnStatus = false, boolean returnStdout = false ) {
ContextRegistry.registerDefaultContext(this) ContextRegistry.registerDefaultContext(this)
Cmd cmd = new Cmd(script, returnStatus, returnStdout) Cmd cmd = new Cmd(script, returnStatus, returnStdout)

9
vars/ringCommand.groovy Normal file
View File

@@ -0,0 +1,9 @@
import ru.pulsar.jenkins.library.ioc.ContextRegistry
import ru.pulsar.jenkins.library.steps.RingCommand
def call(String script ) {
ContextRegistry.registerDefaultContext(this)
RingCommand ringCommand = new RingCommand(script)
return ringCommand.run()
}