mirror of
https://github.com/SAP/jenkins-library.git
synced 2024-12-12 10:55:20 +02:00
TransportRequestUploadFile migration to Go - Git commit scan (#3094)
UploadFile requestid/changedocid retrieval - migrate Git commit history traversal to GO code
This commit is contained in:
parent
61b33ec66e
commit
f88751feb1
@ -4,6 +4,7 @@ import com.cloudbees.groovy.cps.NonCPS
|
||||
|
||||
public class StepHelpers {
|
||||
|
||||
@Deprecated // use go implementation instead
|
||||
public static def getTransportRequestId(ChangeManagement cm, def script, Map configuration) {
|
||||
|
||||
def transportRequestId = configuration.transportRequestId
|
||||
@ -43,8 +44,8 @@ public class StepHelpers {
|
||||
transportRequestId
|
||||
}
|
||||
|
||||
@Deprecated // use go implementation instead
|
||||
public static getChangeDocumentId(ChangeManagement cm, def script, Map configuration) {
|
||||
|
||||
def changeDocumentId = configuration.changeDocumentId
|
||||
|
||||
if(changeDocumentId?.trim()) {
|
||||
@ -82,6 +83,92 @@ public class StepHelpers {
|
||||
return changeDocumentId
|
||||
}
|
||||
|
||||
public static def getTransportRequestId(def script, Map configuration) {
|
||||
|
||||
def transportRequestId = configuration.transportRequestId
|
||||
|
||||
if(transportRequestId?.trim()) {
|
||||
|
||||
script.echo "[INFO] transportRequestId '${transportRequestId}' retrieved from parameters."
|
||||
return transportRequestId
|
||||
|
||||
}
|
||||
|
||||
transportRequestId = script.commonPipelineEnvironment.getValue('transportRequestId')
|
||||
|
||||
if(transportRequestId?.trim()) {
|
||||
script.echo "[INFO] transportRequestId '${transportRequestId}' retrieved from common pipeline environment."
|
||||
return transportRequestId
|
||||
}
|
||||
|
||||
script.echo "[INFO] Retrieving transportRequestId from commit history [" +
|
||||
"from: ${configuration.changeManagement.git.from}, " +
|
||||
"to: ${configuration.changeManagement.git.to}]." +
|
||||
"transportRequestLabel: '${configuration.changeManagement.transportRequestLabel}']."
|
||||
|
||||
script.transportRequestReqIDFromGit(script: this,
|
||||
gitFrom: configuration.changeManagement.git.from,
|
||||
gitTo: configuration.changeManagement.git.to,
|
||||
transportRequestLabel: configuration.changeManagement.transportRequestLabel
|
||||
)
|
||||
|
||||
transportRequestId = script.commonPipelineEnvironment.getValue('transportRequestId')
|
||||
if(transportRequestId != null) {
|
||||
script.echo "[INFO] transportRequestId '${transportRequestId}' retrieved from commit history"
|
||||
}
|
||||
else{
|
||||
script.echo "[WARN] Cannot retrieve transportRequestId from commit history [" +
|
||||
"from: ${configuration.changeManagement.git.from}, " +
|
||||
"to: ${configuration.changeManagement.git.to}, " +
|
||||
"transportRequestLabel: '${configuration.changeManagement.transportRequestLabel}']."
|
||||
}
|
||||
|
||||
return transportRequestId
|
||||
}
|
||||
|
||||
public static getChangeDocumentId(def script, Map configuration) {
|
||||
def changeDocumentId = configuration.changeDocumentId
|
||||
|
||||
if(changeDocumentId?.trim()) {
|
||||
|
||||
script.echo "[INFO] changeDocumentId '${changeDocumentId}' retrieved from parameters."
|
||||
return changeDocumentId
|
||||
}
|
||||
|
||||
changeDocumentId = script.commonPipelineEnvironment.getValue('changeDocumentId')
|
||||
|
||||
if(changeDocumentId?.trim()) {
|
||||
|
||||
script.echo "[INFO] changeDocumentId '${changeDocumentId}' retrieved from common pipeline environment."
|
||||
return changeDocumentId
|
||||
}
|
||||
|
||||
script.echo "[INFO] Retrieving changeDocumentId from commit history [" +
|
||||
"from: ${configuration.changeManagement.git.from}, " +
|
||||
"to: ${configuration.changeManagement.git.to}, " +
|
||||
"changeDocumentLabel: '${configuration.changeManagement.changeDocumentLabel}']."
|
||||
|
||||
script.transportRequestDocIDFromGit(script: this,
|
||||
gitFrom: configuration.changeManagement.git.from,
|
||||
gitTo: configuration.changeManagement.git.to,
|
||||
changeDocumentLabel: configuration.changeManagement.changeDocumentLabel
|
||||
)
|
||||
|
||||
changeDocumentId = script.commonPipelineEnvironment.getValue('changeDocumentId')
|
||||
|
||||
if(changeDocumentId == null) {
|
||||
script.echo "[WARN] Cannot retrieve changeDocumentId from commit history [" +
|
||||
"from: ${configuration.changeManagement.git.from}, " +
|
||||
"to: ${configuration.changeManagement.git.to}, " +
|
||||
"changeDocumentLabel: '${configuration.changeManagement.changeDocumentLabel}']."
|
||||
}
|
||||
else {
|
||||
script.echo "[INFO] changeDocumentId '${changeDocumentId}' retrieved from commit history"
|
||||
}
|
||||
|
||||
return changeDocumentId
|
||||
}
|
||||
|
||||
@NonCPS
|
||||
static BackendType getBackendTypeAndLogInfoIfCMIntegrationDisabled(def script, Map configuration) {
|
||||
|
||||
|
@ -62,45 +62,59 @@ public class TransportRequestUploadFileTest extends BasePiperTest {
|
||||
@Test
|
||||
public void changeDocumentIdNotProvidedSOLMANTest() {
|
||||
|
||||
// we expect the failure only for SOLMAN (which is the default).
|
||||
// Use case for CTS without change document id is checked by the
|
||||
// straight forward test case for CTS
|
||||
def calledWithParameters = null
|
||||
|
||||
helper.registerAllowedMethod( 'piperExecuteBin', [Map, String, String, List],
|
||||
{
|
||||
params, stepName, metaData, creds ->
|
||||
if(stepName.equals("transportRequestDocIDFromGit")) {
|
||||
calledWithParameters = params
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
thrown.expect(IllegalArgumentException)
|
||||
thrown.expectMessage("Change document id not provided (parameter: 'changeDocumentId' provided to the step call or via commit history).")
|
||||
|
||||
ChangeManagement cm = new ChangeManagement(nullScript) {
|
||||
String getChangeDocumentId(
|
||||
String from,
|
||||
String to,
|
||||
String pattern,
|
||||
String format
|
||||
) {
|
||||
throw new ChangeManagementException('Cannot retrieve changeId from git commits.')
|
||||
}
|
||||
}
|
||||
stepRule.step.transportRequestUploadFile(script: nullScript, transportRequestId: '001', applicationId: 'app', filePath: '/path',
|
||||
changeManagement: [
|
||||
type: 'SOLMAN',
|
||||
endpoint: 'https://example.org/cm',
|
||||
clientOpts: '--client opts'
|
||||
],
|
||||
credentialsId: 'CM'
|
||||
)
|
||||
|
||||
stepRule.step.transportRequestUploadFile(script: nullScript, transportRequestId: '001', applicationId: 'app', filePath: '/path', cmUtils: cm)
|
||||
assert calledWithParameters != null
|
||||
}
|
||||
|
||||
@Test
|
||||
public void transportRequestIdNotProvidedTest() {
|
||||
|
||||
ChangeManagement cm = new ChangeManagement(nullScript) {
|
||||
String getTransportRequestId(
|
||||
String from,
|
||||
String to,
|
||||
String pattern,
|
||||
String format
|
||||
) {
|
||||
throw new ChangeManagementException('Cannot retrieve transport request id from git commits.')
|
||||
def calledWithParameters = null
|
||||
|
||||
helper.registerAllowedMethod( 'piperExecuteBin', [Map, String, String, List],
|
||||
{
|
||||
params, stepName, metaData, creds ->
|
||||
if(stepName.equals("transportRequestReqIDFromGit")) {
|
||||
calledWithParameters = params
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
thrown.expect(IllegalArgumentException)
|
||||
thrown.expectMessage("Transport request id not provided (parameter: 'transportRequestId' provided to the step call or via commit history).")
|
||||
|
||||
stepRule.step.transportRequestUploadFile(script: nullScript, changeDocumentId: '001', applicationId: 'app', filePath: '/path', cmUtils: cm)
|
||||
stepRule.step.transportRequestUploadFile(script: nullScript, changeDocumentId: '001', applicationId: 'app', filePath: '/path',
|
||||
changeManagement: [
|
||||
type: 'SOLMAN',
|
||||
endpoint: 'https://example.org/cm',
|
||||
clientOpts: '--client opts'
|
||||
],
|
||||
credentialsId: 'CM'
|
||||
)
|
||||
|
||||
assert calledWithParameters != null
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -158,6 +158,7 @@ class StepHelpersTest extends BasePiperTest {
|
||||
assert transportRequestId == null
|
||||
}
|
||||
|
||||
@Test
|
||||
public void changeDocumentIdViaCommonPipelineEnvironmentTest() {
|
||||
|
||||
nullScript.commonPipelineEnvironment.setChangeDocumentId('002')
|
||||
@ -209,4 +210,178 @@ class StepHelpersTest extends BasePiperTest {
|
||||
|
||||
assert changeDocumentId == null
|
||||
}
|
||||
|
||||
@Test
|
||||
public void reqidViaConfigTest() {
|
||||
|
||||
nullScript.commonPipelineEnvironment.setValue('transportRequestId', 'unused')
|
||||
|
||||
def calledWithParameters = null
|
||||
|
||||
helper.registerAllowedMethod( 'piperExecuteBin', [Map, String, String, List],
|
||||
{
|
||||
params, stepName, metaData, creds ->
|
||||
if(stepName.equals("transportRequestReqIDFromGit")) {
|
||||
calledWithParameters = params
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
def transportRequestId = StepHelpers.getTransportRequestId(nullScript, [transportRequestId: '100'])
|
||||
|
||||
assert transportRequestId == '100'
|
||||
assert calledWithParameters == null
|
||||
}
|
||||
|
||||
@Test
|
||||
public void reqidViaCommonPipelineEnvironmentTest() {
|
||||
|
||||
nullScript.commonPipelineEnvironment.setValue('transportRequestId', '200')
|
||||
|
||||
def calledWithParameters = null
|
||||
|
||||
helper.registerAllowedMethod( 'piperExecuteBin', [Map, String, String, List],
|
||||
{
|
||||
params, stepName, metaData, creds ->
|
||||
if(stepName.equals("transportRequestReqIDFromGit")) {
|
||||
calledWithParameters = params
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
def transportRequestId = StepHelpers.getTransportRequestId(nullScript, params)
|
||||
|
||||
assert transportRequestId == '200'
|
||||
assert calledWithParameters == null
|
||||
}
|
||||
|
||||
@Test
|
||||
public void reqidViaCommitHistoryTest() {
|
||||
|
||||
def calledWithParameters = null
|
||||
|
||||
helper.registerAllowedMethod( 'piperExecuteBin', [Map, String, String, List],
|
||||
{
|
||||
params, stepName, metaData, creds ->
|
||||
if(stepName.equals("transportRequestReqIDFromGit")) {
|
||||
nullScript.commonPipelineEnvironment.setValue('transportRequestId', '300')
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
def transportRequestId = StepHelpers.getTransportRequestId(nullScript, params)
|
||||
|
||||
assert transportRequestId == '300'
|
||||
assert nullScript.commonPipelineEnvironment.getValue('transportRequestId') == '300'
|
||||
}
|
||||
|
||||
@Test
|
||||
public void reqidNotProvidedTest() {
|
||||
|
||||
def calledWithParameters = null
|
||||
|
||||
helper.registerAllowedMethod( 'piperExecuteBin', [Map, String, String, List],
|
||||
{
|
||||
params, stepName, metaData, creds ->
|
||||
if(stepName.equals("transportRequestReqIDFromGit")) {
|
||||
calledWithParameters = params
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
loggingRule.expect('[INFO] Retrieving transportRequestId from commit history')
|
||||
loggingRule.expect('[WARN] Cannot retrieve transportRequestId from commit history')
|
||||
|
||||
def transportRequestId = StepHelpers.getTransportRequestId(nullScript, params)
|
||||
|
||||
assert transportRequestId == null
|
||||
assert calledWithParameters != null
|
||||
}
|
||||
|
||||
@Test
|
||||
public void docidViaConfigTest() {
|
||||
|
||||
nullScript.commonPipelineEnvironment.setValue('changeDocumentId', 'unused')
|
||||
|
||||
def calledWithParameters = null
|
||||
|
||||
helper.registerAllowedMethod( 'piperExecuteBin', [Map, String, String, List],
|
||||
{
|
||||
params, stepName, metaData, creds ->
|
||||
if(stepName.equals("transportRequestDocIDFromGit")) {
|
||||
calledWithParameters = params
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
def changeDocumentId = StepHelpers.getChangeDocumentId(nullScript, [changeDocumentId: '100'])
|
||||
|
||||
assert changeDocumentId == '100'
|
||||
assert calledWithParameters == null
|
||||
}
|
||||
|
||||
@Test
|
||||
public void docidViaCommonPipelineEnvironmentTest() {
|
||||
|
||||
nullScript.commonPipelineEnvironment.setValue('changeDocumentId', '200')
|
||||
|
||||
def calledWithParameters = null
|
||||
|
||||
helper.registerAllowedMethod( 'piperExecuteBin', [Map, String, String, List],
|
||||
{
|
||||
params, stepName, metaData, creds ->
|
||||
if(stepName.equals("transportRequestDocIDFromGit")) {
|
||||
calledWithParameters = params
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
def changeDocumentId = StepHelpers.getChangeDocumentId(nullScript, params)
|
||||
|
||||
assert changeDocumentId == '200'
|
||||
assert calledWithParameters == null
|
||||
}
|
||||
|
||||
@Test
|
||||
public void docidViaCommitHistoryTest() {
|
||||
|
||||
def calledWithParameters = null
|
||||
|
||||
helper.registerAllowedMethod( 'piperExecuteBin', [Map, String, String, List],
|
||||
{
|
||||
params, stepName, metaData, creds ->
|
||||
if(stepName.equals("transportRequestDocIDFromGit")) {
|
||||
nullScript.commonPipelineEnvironment.setValue('changeDocumentId', '300')
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
def changeDocumentId = StepHelpers.getChangeDocumentId(nullScript, params)
|
||||
|
||||
assert changeDocumentId == '300'
|
||||
assert nullScript.commonPipelineEnvironment.getValue('changeDocumentId') == '300'
|
||||
}
|
||||
|
||||
@Test
|
||||
public void docidNotProvidedTest() {
|
||||
|
||||
def calledWithParameters = null
|
||||
|
||||
helper.registerAllowedMethod( 'piperExecuteBin', [Map, String, String, List],
|
||||
{
|
||||
params, stepName, metaData, creds ->
|
||||
if(stepName.equals("transportRequestDocIDFromGit")) {
|
||||
calledWithParameters = params
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
loggingRule.expect('[INFO] Retrieving changeDocumentId from commit history')
|
||||
loggingRule.expect('[WARN] Cannot retrieve changeDocumentId from commit history')
|
||||
|
||||
def changeDocumentId = StepHelpers.getChangeDocumentId(nullScript, params)
|
||||
|
||||
assert changeDocumentId == null
|
||||
assert calledWithParameters != null
|
||||
}
|
||||
}
|
||||
|
@ -211,10 +211,10 @@ void call(Map parameters = [:]) {
|
||||
def changeDocumentId = null
|
||||
|
||||
if(backendType == BackendType.SOLMAN) {
|
||||
changeDocumentId = getChangeDocumentId(cm, script, configuration)
|
||||
changeDocumentId = getChangeDocumentId(script, configuration)
|
||||
}
|
||||
|
||||
def transportRequestId = getTransportRequestId(cm, script, configuration)
|
||||
def transportRequestId = getTransportRequestId(script, configuration)
|
||||
|
||||
configHelper
|
||||
.mixin([changeDocumentId: changeDocumentId?.trim() ?: null,
|
||||
|
Loading…
Reference in New Issue
Block a user