You've already forked jenkins-lib
mirror of
https://github.com/firstBitMarksistskaya/jenkins-lib.git
synced 2025-08-25 20:09:25 +02:00
Добавление шага ringCommand
This commit is contained in:
@@ -36,6 +36,8 @@ interface IStepExecutor {
|
||||
|
||||
def cmd(String script)
|
||||
|
||||
def ringCommand(String script)
|
||||
|
||||
void tool(String toolName)
|
||||
|
||||
def withCredentials(List bindings, Closure body)
|
||||
|
@@ -62,6 +62,11 @@ class StepExecutor implements IStepExecutor {
|
||||
return steps.cmd(script, returnStatus, returnStdout)
|
||||
}
|
||||
|
||||
@Override
|
||||
def ringCommand(String script) {
|
||||
return steps.ringCommand(script)
|
||||
}
|
||||
|
||||
@Override
|
||||
void tool(String toolName) {
|
||||
steps.tool toolName
|
||||
|
@@ -34,7 +34,7 @@ class DesignerToEdtFormatTransformation implements Serializable {
|
||||
|
||||
def env = steps.env();
|
||||
|
||||
String workspaceDir = FileUtils.getFilePath("$env.WORKSPACE/$WORKSPACE").getRemote()
|
||||
def workspaceDir = FileUtils.getFilePath("$env.WORKSPACE/$WORKSPACE")
|
||||
def srcDir = config.srcDir
|
||||
def configurationRoot = FileUtils.getFilePath("$env.WORKSPACE/$srcDir")
|
||||
def edtVersionForRing = EDT.ringModule(config)
|
||||
@@ -47,10 +47,7 @@ class DesignerToEdtFormatTransformation implements Serializable {
|
||||
|
||||
def ringOpts = [Constants.DEFAULT_RING_OPTS]
|
||||
steps.withEnv(ringOpts) {
|
||||
String ringMessage = steps.cmd(ringCommand, false, true)
|
||||
if (ringMessage.contains("error")) {
|
||||
steps.error(ringMessage)
|
||||
}
|
||||
steps.ringCommand(ringCommand)
|
||||
}
|
||||
|
||||
steps.zip(WORKSPACE, WORKSPACE_ZIP)
|
||||
|
22
src/ru/pulsar/jenkins/library/steps/RingCommand.groovy
Normal file
22
src/ru/pulsar/jenkins/library/steps/RingCommand.groovy
Normal 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)
|
||||
}
|
||||
}
|
||||
}
|
@@ -29,14 +29,17 @@ class CmdTest {
|
||||
final String script = "echo hello";
|
||||
Cmd cmd = new Cmd(script);
|
||||
|
||||
when(steps.bat(anyString(), anyBoolean(), anyBoolean(), anyString())).thenReturn(0);
|
||||
when(steps.sh(anyString(), anyBoolean(), anyBoolean(), anyString())).thenReturn(0);
|
||||
|
||||
// when
|
||||
int run = cmd.run();
|
||||
Object run = cmd.run();
|
||||
|
||||
// then
|
||||
verify(steps).isUnix();
|
||||
assertThat(steps).satisfiesAnyOf(
|
||||
steps -> verify(steps).bat(contains(script), eq(false), anyString()),
|
||||
steps -> verify(steps).sh(contains(script), eq(false), anyString())
|
||||
steps -> verify(steps).bat(contains(script), eq(false), eq(false), anyString()),
|
||||
steps -> verify(steps).sh(contains(script), eq(false), eq(false), anyString())
|
||||
);
|
||||
|
||||
assertThat(run).isEqualTo(0);
|
||||
@@ -49,8 +52,8 @@ class CmdTest {
|
||||
Cmd cmd = new Cmd(script);
|
||||
|
||||
String thrownText = "failed";
|
||||
when(steps.bat(anyString(), anyBoolean(), anyString())).thenThrow(new Error(thrownText));
|
||||
when(steps.sh(anyString(), anyBoolean(), anyString())).thenThrow(new Error(thrownText));
|
||||
when(steps.bat(anyString(), anyBoolean(), anyBoolean(), anyString())).thenThrow(new Error(thrownText));
|
||||
when(steps.sh(anyString(), anyBoolean(), anyBoolean(), anyString())).thenThrow(new Error(thrownText));
|
||||
|
||||
// when
|
||||
Throwable thrown = catchThrowable(cmd::run);
|
||||
@@ -59,8 +62,8 @@ class CmdTest {
|
||||
// then
|
||||
verify(steps).isUnix();
|
||||
assertThat(steps).satisfiesAnyOf(
|
||||
steps -> verify(steps).bat(contains(script), eq(false), anyString()),
|
||||
steps -> verify(steps).sh(contains(script), eq(false), anyString())
|
||||
steps -> verify(steps).bat(contains(script), eq(false), eq(false), anyString()),
|
||||
steps -> verify(steps).sh(contains(script), eq(false), eq(false), anyString())
|
||||
);
|
||||
}
|
||||
|
||||
@@ -70,17 +73,17 @@ class CmdTest {
|
||||
final String script = "false";
|
||||
Cmd cmd = new Cmd(script, true);
|
||||
|
||||
when(steps.bat(anyString(), anyBoolean(), anyString())).thenReturn(1);
|
||||
when(steps.sh(anyString(), anyBoolean(), anyString())).thenReturn(1);
|
||||
when(steps.bat(anyString(), anyBoolean(), anyBoolean(), anyString())).thenReturn(1);
|
||||
when(steps.sh(anyString(), anyBoolean(), anyBoolean(), anyString())).thenReturn(1);
|
||||
|
||||
// when
|
||||
int run = cmd.run();
|
||||
Object run = cmd.run();
|
||||
|
||||
// then
|
||||
verify(steps).isUnix();
|
||||
assertThat(steps).satisfiesAnyOf(
|
||||
steps -> verify(steps).bat(contains(script), eq(true), anyString()),
|
||||
steps -> verify(steps).sh(contains(script), eq(true), anyString())
|
||||
steps -> verify(steps).bat(contains(script), eq(true), eq(false), anyString()),
|
||||
steps -> verify(steps).sh(contains(script), eq(true), eq(false), anyString())
|
||||
);
|
||||
|
||||
assertThat(run).isEqualTo(1);
|
||||
|
@@ -1,7 +1,7 @@
|
||||
import ru.pulsar.jenkins.library.steps.Cmd
|
||||
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)
|
||||
|
||||
Cmd cmd = new Cmd(script, returnStatus, returnStdout)
|
||||
|
9
vars/ringCommand.groovy
Normal file
9
vars/ringCommand.groovy
Normal 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()
|
||||
}
|
Reference in New Issue
Block a user