You've already forked jenkins-lib
forked from jenkins/jenkins-lib
Merge pull request #113 from ivanmolodec/develop
This commit is contained in:
@@ -12,9 +12,9 @@ interface IStepExecutor {
|
|||||||
|
|
||||||
boolean isUnix()
|
boolean isUnix()
|
||||||
|
|
||||||
int sh(String script, boolean returnStatus, String encoding)
|
def sh(String script, boolean returnStatus, boolean returnStdout, String encoding)
|
||||||
|
|
||||||
int bat(String script, boolean returnStatus, String encoding)
|
def bat(String script, boolean returnStatus, boolean returnStdout, String encoding)
|
||||||
|
|
||||||
String libraryResource(String path)
|
String libraryResource(String path)
|
||||||
|
|
||||||
@@ -30,9 +30,13 @@ interface IStepExecutor {
|
|||||||
|
|
||||||
void echo(message)
|
void echo(message)
|
||||||
|
|
||||||
int cmd(String script, boolean returnStatus)
|
def cmd(String script, boolean returnStatus, boolean returnStdout)
|
||||||
|
|
||||||
int cmd(String script)
|
def cmd(String script, boolean returnStatus)
|
||||||
|
|
||||||
|
def cmd(String script)
|
||||||
|
|
||||||
|
def ringCommand(String script)
|
||||||
|
|
||||||
void tool(String toolName)
|
void tool(String toolName)
|
||||||
|
|
||||||
|
@@ -23,13 +23,13 @@ class StepExecutor implements IStepExecutor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
int sh(String script, boolean returnStatus, String encoding) {
|
def sh(String script, boolean returnStatus, boolean returnStdout, String encoding) {
|
||||||
steps.sh script: script, returnStatus: returnStatus, encoding: encoding
|
steps.sh script: script, returnStatus: returnStatus, returnStdout: returnStdout, encoding: encoding
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
int bat(String script, boolean returnStatus, String encoding) {
|
def bat(String script, boolean returnStatus, boolean returnStdout, String encoding) {
|
||||||
steps.bat script: script, returnStatus: returnStatus, encoding: encoding
|
steps.bat script: script, returnStatus: returnStatus, returnStdout: returnStdout, encoding: encoding
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -58,8 +58,13 @@ class StepExecutor implements IStepExecutor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
int cmd(String script, boolean returnStatus = false) {
|
def cmd(String script, boolean returnStatus = false, boolean returnStdout = false) {
|
||||||
return steps.cmd(script, returnStatus)
|
return steps.cmd(script, returnStatus, returnStdout)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
def ringCommand(String script) {
|
||||||
|
return steps.ringCommand(script)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -7,22 +7,28 @@ class Cmd implements Serializable {
|
|||||||
|
|
||||||
private String script;
|
private String script;
|
||||||
private boolean returnStatus
|
private boolean returnStatus
|
||||||
|
private boolean returnStdout
|
||||||
private String encoding = 'UTF-8'
|
private String encoding = 'UTF-8'
|
||||||
|
|
||||||
Cmd(String script, boolean returnStatus = false) {
|
Cmd(String script, boolean returnStatus = false, boolean returnStdout = false) {
|
||||||
this.script = script
|
this.script = script
|
||||||
this.returnStatus = returnStatus
|
this.returnStatus = returnStatus
|
||||||
|
this.returnStdout = returnStdout
|
||||||
};
|
};
|
||||||
|
|
||||||
int run() {
|
def run() {
|
||||||
IStepExecutor steps = ContextRegistry.getContext().getStepExecutor()
|
IStepExecutor steps = ContextRegistry.getContext().getStepExecutor()
|
||||||
|
|
||||||
int returnValue
|
def returnValue
|
||||||
|
|
||||||
|
if (returnStatus & returnStdout) {
|
||||||
|
steps.error("returnStatus and returnStdout are not supported at the same time")
|
||||||
|
}
|
||||||
|
|
||||||
if (steps.isUnix()) {
|
if (steps.isUnix()) {
|
||||||
returnValue = steps.sh("$script", returnStatus, encoding)
|
returnValue = steps.sh("$script", returnStatus, returnStdout, encoding)
|
||||||
} else {
|
} else {
|
||||||
returnValue = steps.bat("chcp 65001 > nul \n$script", returnStatus, encoding)
|
returnValue = steps.bat("chcp 65001 > nul \n$script", returnStatus, returnStdout, encoding)
|
||||||
}
|
}
|
||||||
|
|
||||||
return returnValue
|
return returnValue
|
||||||
|
@@ -4,7 +4,6 @@ package ru.pulsar.jenkins.library.steps
|
|||||||
import ru.pulsar.jenkins.library.IStepExecutor
|
import ru.pulsar.jenkins.library.IStepExecutor
|
||||||
import ru.pulsar.jenkins.library.configuration.JobConfiguration
|
import ru.pulsar.jenkins.library.configuration.JobConfiguration
|
||||||
import ru.pulsar.jenkins.library.ioc.ContextRegistry
|
import ru.pulsar.jenkins.library.ioc.ContextRegistry
|
||||||
import ru.pulsar.jenkins.library.utils.Constants
|
|
||||||
import ru.pulsar.jenkins.library.utils.EDT
|
import ru.pulsar.jenkins.library.utils.EDT
|
||||||
import ru.pulsar.jenkins.library.utils.FileUtils
|
import ru.pulsar.jenkins.library.utils.FileUtils
|
||||||
import ru.pulsar.jenkins.library.utils.Logger
|
import ru.pulsar.jenkins.library.utils.Logger
|
||||||
@@ -45,10 +44,7 @@ class DesignerToEdtFormatTransformation implements Serializable {
|
|||||||
|
|
||||||
def ringCommand = "ring $edtVersionForRing workspace import --configuration-files \"$configurationRoot\" --project-name $PROJECT_NAME --workspace-location \"$workspaceDir\""
|
def ringCommand = "ring $edtVersionForRing workspace import --configuration-files \"$configurationRoot\" --project-name $PROJECT_NAME --workspace-location \"$workspaceDir\""
|
||||||
|
|
||||||
def ringOpts = [Constants.DEFAULT_RING_OPTS]
|
steps.ringCommand(ringCommand)
|
||||||
steps.withEnv(ringOpts) {
|
|
||||||
steps.cmd(ringCommand)
|
|
||||||
}
|
|
||||||
|
|
||||||
steps.zip(WORKSPACE, WORKSPACE_ZIP)
|
steps.zip(WORKSPACE, WORKSPACE_ZIP)
|
||||||
steps.stash(WORKSPACE_ZIP_STASH, WORKSPACE_ZIP)
|
steps.stash(WORKSPACE_ZIP_STASH, WORKSPACE_ZIP)
|
||||||
|
@@ -5,7 +5,6 @@ import ru.pulsar.jenkins.library.IStepExecutor
|
|||||||
import ru.pulsar.jenkins.library.configuration.JobConfiguration
|
import ru.pulsar.jenkins.library.configuration.JobConfiguration
|
||||||
import ru.pulsar.jenkins.library.configuration.SourceFormat
|
import ru.pulsar.jenkins.library.configuration.SourceFormat
|
||||||
import ru.pulsar.jenkins.library.ioc.ContextRegistry
|
import ru.pulsar.jenkins.library.ioc.ContextRegistry
|
||||||
import ru.pulsar.jenkins.library.utils.Constants
|
|
||||||
import ru.pulsar.jenkins.library.utils.EDT
|
import ru.pulsar.jenkins.library.utils.EDT
|
||||||
import ru.pulsar.jenkins.library.utils.FileUtils
|
import ru.pulsar.jenkins.library.utils.FileUtils
|
||||||
import ru.pulsar.jenkins.library.utils.Logger
|
import ru.pulsar.jenkins.library.utils.Logger
|
||||||
@@ -48,10 +47,7 @@ class EdtToDesignerFormatTransformation implements Serializable {
|
|||||||
|
|
||||||
def ringCommand = "ring $edtVersionForRing workspace export --workspace-location \"$workspaceDir\" --project \"$projectDir\" --configuration-files \"$configurationRoot\""
|
def ringCommand = "ring $edtVersionForRing workspace export --workspace-location \"$workspaceDir\" --project \"$projectDir\" --configuration-files \"$configurationRoot\""
|
||||||
|
|
||||||
def ringOpts = [Constants.DEFAULT_RING_OPTS]
|
steps.ringCommand(ringCommand)
|
||||||
steps.withEnv(ringOpts) {
|
|
||||||
steps.cmd(ringCommand)
|
|
||||||
}
|
|
||||||
|
|
||||||
steps.zip(CONFIGURATION_DIR, CONFIGURATION_ZIP)
|
steps.zip(CONFIGURATION_DIR, CONFIGURATION_ZIP)
|
||||||
steps.stash(CONFIGURATION_ZIP_STASH, CONFIGURATION_ZIP)
|
steps.stash(CONFIGURATION_ZIP_STASH, CONFIGURATION_ZIP)
|
||||||
|
@@ -4,7 +4,6 @@ import ru.pulsar.jenkins.library.IStepExecutor
|
|||||||
import ru.pulsar.jenkins.library.configuration.JobConfiguration
|
import ru.pulsar.jenkins.library.configuration.JobConfiguration
|
||||||
import ru.pulsar.jenkins.library.configuration.SourceFormat
|
import ru.pulsar.jenkins.library.configuration.SourceFormat
|
||||||
import ru.pulsar.jenkins.library.ioc.ContextRegistry
|
import ru.pulsar.jenkins.library.ioc.ContextRegistry
|
||||||
import ru.pulsar.jenkins.library.utils.Constants
|
|
||||||
import ru.pulsar.jenkins.library.utils.EDT
|
import ru.pulsar.jenkins.library.utils.EDT
|
||||||
import ru.pulsar.jenkins.library.utils.FileUtils
|
import ru.pulsar.jenkins.library.utils.FileUtils
|
||||||
import ru.pulsar.jenkins.library.utils.Logger
|
import ru.pulsar.jenkins.library.utils.Logger
|
||||||
@@ -52,11 +51,8 @@ class EdtValidate implements Serializable {
|
|||||||
Logger.println("Выполнение валидации EDT")
|
Logger.println("Выполнение валидации EDT")
|
||||||
|
|
||||||
def ringCommand = "ring $edtVersionForRing workspace validate --workspace-location \"$workspaceLocation\" --file \"$resultFile\" $projectList"
|
def ringCommand = "ring $edtVersionForRing workspace validate --workspace-location \"$workspaceLocation\" --file \"$resultFile\" $projectList"
|
||||||
def ringOpts = [Constants.DEFAULT_RING_OPTS]
|
steps.catchError {
|
||||||
steps.withEnv(ringOpts) {
|
steps.ringCommand(ringCommand)
|
||||||
steps.catchError {
|
|
||||||
steps.cmd(ringCommand)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
steps.archiveArtifacts("$DesignerToEdtFormatTransformation.WORKSPACE/.metadata/.log")
|
steps.archiveArtifacts("$DesignerToEdtFormatTransformation.WORKSPACE/.metadata/.log")
|
||||||
|
30
src/ru/pulsar/jenkins/library/steps/RingCommand.groovy
Normal file
30
src/ru/pulsar/jenkins/library/steps/RingCommand.groovy
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
package ru.pulsar.jenkins.library.steps
|
||||||
|
|
||||||
|
import ru.pulsar.jenkins.library.IStepExecutor
|
||||||
|
import ru.pulsar.jenkins.library.ioc.ContextRegistry
|
||||||
|
import ru.pulsar.jenkins.library.utils.Constants
|
||||||
|
|
||||||
|
class RingCommand implements Serializable {
|
||||||
|
|
||||||
|
private String script
|
||||||
|
private boolean returnStatus
|
||||||
|
private boolean returnStdout
|
||||||
|
|
||||||
|
RingCommand(String script) {
|
||||||
|
this.script = script
|
||||||
|
this.returnStatus = false
|
||||||
|
this.returnStdout = true
|
||||||
|
};
|
||||||
|
|
||||||
|
def run() {
|
||||||
|
IStepExecutor steps = ContextRegistry.getContext().getStepExecutor()
|
||||||
|
|
||||||
|
def ringOpts = [Constants.DEFAULT_RING_OPTS]
|
||||||
|
steps.withEnv(ringOpts) {
|
||||||
|
String ringMessage = steps.cmd(script, returnStatus, returnStdout)
|
||||||
|
if (ringMessage.contains("error")) {
|
||||||
|
steps.error(ringMessage)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -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);
|
||||||
|
@@ -1,9 +1,9 @@
|
|||||||
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) {
|
def call(String script, boolean returnStatus = false, boolean returnStdout = false ) {
|
||||||
ContextRegistry.registerDefaultContext(this)
|
ContextRegistry.registerDefaultContext(this)
|
||||||
|
|
||||||
Cmd cmd = new Cmd(script, returnStatus)
|
Cmd cmd = new Cmd(script, returnStatus, returnStdout)
|
||||||
return cmd.run()
|
return cmd.run()
|
||||||
}
|
}
|
||||||
|
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