mirror of
https://github.com/SAP/jenkins-library.git
synced 2025-01-18 05:18:24 +02:00
Merge remote-tracking branch 'github/master' into HEAD
This commit is contained in:
commit
cc52cbd274
@ -7,6 +7,8 @@ Creates
|
||||
* a Transport Request for a Change Document on the Solution Manager (type `SOLMAN`) or
|
||||
* a Transport Request inside an ABAP system (type`CTS`)
|
||||
|
||||
The id of the transport request is availabe via [commonPipelineEnvironment.getTransportRequestId()](commonPipelineEnvironment.md)
|
||||
|
||||
## Prerequisites
|
||||
|
||||
* **[Change Management Client 2.0.0 or compatible version](http://central.maven.org/maven2/com/sap/devops/cmclient/dist.cli/)** - available for download on Maven Central.
|
||||
@ -97,7 +99,7 @@ The parameters can also be provided when the step is invoked. For examples see b
|
||||
|
||||
## Return value
|
||||
|
||||
The id of the Transport Request that has been created.
|
||||
none
|
||||
|
||||
## Exceptions
|
||||
|
||||
|
@ -4,57 +4,64 @@ import com.cloudbees.groovy.cps.NonCPS
|
||||
|
||||
public class StepHelpers {
|
||||
|
||||
@NonCPS
|
||||
public static def getTransportRequestId(ChangeManagement cm, def step, Map configuration) {
|
||||
public static def getTransportRequestId(ChangeManagement cm, def script, Map configuration) {
|
||||
|
||||
def transportRequestId = configuration.transportRequestId
|
||||
|
||||
if(transportRequestId?.trim()) {
|
||||
|
||||
step.echo "[INFO] Transport request id '${transportRequestId}' retrieved from parameters."
|
||||
script.echo "[INFO] Transport request id '${transportRequestId}' retrieved from parameters."
|
||||
return transportRequestId
|
||||
|
||||
} else {
|
||||
|
||||
step.echo "[INFO] Retrieving transport request id from commit history [from: ${configuration.changeManagement.git.from}, to: ${configuration.changeManagement.git.to}]." +
|
||||
" Searching for pattern '${configuration.changeManagement.transportRequestLabel}'. Searching with format '${configuration.changeManagement.git.format}'."
|
||||
|
||||
try {
|
||||
transportRequestId = cm.getTransportRequestId(
|
||||
configuration.changeManagement.git.from,
|
||||
configuration.changeManagement.git.to,
|
||||
configuration.changeManagement.transportRequestLabel,
|
||||
configuration.changeManagement.git.format
|
||||
)
|
||||
|
||||
step.echo "[INFO] Transport request id '${transportRequestId}' retrieved from commit history"
|
||||
|
||||
} catch(ChangeManagementException ex) {
|
||||
step.echo "[WARN] Cannot retrieve transportRequestId from commit history: ${ex.getMessage()}."
|
||||
}
|
||||
}
|
||||
return transportRequestId
|
||||
|
||||
transportRequestId = script.commonPipelineEnvironment.getTransportRequestId()
|
||||
|
||||
if(transportRequestId?.trim()) {
|
||||
script.echo "[INFO] Transport request id '${transportRequestId}' retrieved from common pipeline environment."
|
||||
return transportRequestId
|
||||
}
|
||||
|
||||
script.echo "[INFO] Retrieving transport request id from commit history [from: ${configuration.changeManagement.git.from}, to: ${configuration.changeManagement.git.to}]." +
|
||||
" Searching for pattern '${configuration.changeManagement.transportRequestLabel}'. Searching with format '${configuration.changeManagement.git.format}'."
|
||||
|
||||
try {
|
||||
transportRequestId = cm.getTransportRequestId(
|
||||
configuration.changeManagement.git.from,
|
||||
configuration.changeManagement.git.to,
|
||||
configuration.changeManagement.transportRequestLabel,
|
||||
configuration.changeManagement.git.format
|
||||
)
|
||||
|
||||
script.commonPipelineEnvironment.setTransportRequestId(transportRequestId)
|
||||
script.echo "[INFO] Transport request id '${transportRequestId}' retrieved from commit history"
|
||||
|
||||
} catch(ChangeManagementException ex) {
|
||||
script.echo "[WARN] Cannot retrieve transportRequestId from commit history: ${ex.getMessage()}."
|
||||
}
|
||||
|
||||
transportRequestId
|
||||
}
|
||||
|
||||
@NonCPS
|
||||
public static getChangeDocumentId(ChangeManagement cm, def step, Map configuration) {
|
||||
public static getChangeDocumentId(ChangeManagement cm, def script, Map configuration) {
|
||||
|
||||
def changeDocumentId = configuration.changeDocumentId
|
||||
|
||||
if(changeDocumentId?.trim()) {
|
||||
|
||||
step.echo "[INFO] ChangeDocumentId '${changeDocumentId}' retrieved from parameters."
|
||||
script.echo "[INFO] ChangeDocumentId '${changeDocumentId}' retrieved from parameters."
|
||||
return changeDocumentId
|
||||
}
|
||||
|
||||
changeDocumentId = step.commonPipelineEnvironment.getChangeDocumentId()
|
||||
changeDocumentId = script.commonPipelineEnvironment.getChangeDocumentId()
|
||||
|
||||
if(changeDocumentId?.trim()) {
|
||||
|
||||
step.echo "[INFO] ChangeDocumentId '${changeDocumentId}' retrieved from common pipeline environment."
|
||||
script.echo "[INFO] ChangeDocumentId '${changeDocumentId}' retrieved from common pipeline environment."
|
||||
return changeDocumentId
|
||||
}
|
||||
|
||||
step.echo "[INFO] Retrieving ChangeDocumentId from commit history [from: ${configuration.changeManagement.git.from}, to: ${configuration.changeManagement.git.to}]." +
|
||||
script.echo "[INFO] Retrieving ChangeDocumentId from commit history [from: ${configuration.changeManagement.git.from}, to: ${configuration.changeManagement.git.to}]." +
|
||||
"Searching for pattern '${configuration.changeManagement.changeDocumentLabel}'. Searching with format '${configuration.changeManagement.git.format}'."
|
||||
|
||||
try {
|
||||
@ -65,31 +72,31 @@ public class StepHelpers {
|
||||
configuration.changeManagement.git.format
|
||||
)
|
||||
|
||||
step.echo "[INFO] ChangeDocumentId '${changeDocumentId}' retrieved from commit history"
|
||||
step.commonPipelineEnvironment.setChangeDocumentId(changeDocumentId)
|
||||
script.echo "[INFO] ChangeDocumentId '${changeDocumentId}' retrieved from commit history"
|
||||
script.commonPipelineEnvironment.setChangeDocumentId(changeDocumentId)
|
||||
|
||||
} catch(ChangeManagementException ex) {
|
||||
step.echo "[WARN] Cannot retrieve changeDocumentId from commit history: ${ex.getMessage()}."
|
||||
script.echo "[WARN] Cannot retrieve changeDocumentId from commit history: ${ex.getMessage()}."
|
||||
}
|
||||
|
||||
return changeDocumentId
|
||||
}
|
||||
|
||||
@NonCPS
|
||||
static BackendType getBackendTypeAndLogInfoIfCMIntegrationDisabled(def step, Map configuration) {
|
||||
static BackendType getBackendTypeAndLogInfoIfCMIntegrationDisabled(def script, Map configuration) {
|
||||
|
||||
BackendType backendType
|
||||
|
||||
try {
|
||||
backendType = configuration.changeManagement.type as BackendType
|
||||
} catch(IllegalArgumentException e) {
|
||||
step.error "Invalid backend type: '${configuration.changeManagement.type}'. " +
|
||||
script.error "Invalid backend type: '${configuration.changeManagement.type}'. " +
|
||||
"Valid values: [${BackendType.values().join(', ')}]. " +
|
||||
"Configuration: 'changeManagement/type'."
|
||||
}
|
||||
|
||||
if (backendType == BackendType.NONE) {
|
||||
step.echo "[INFO] Change management integration intentionally switched off. " +
|
||||
script.echo "[INFO] Change management integration intentionally switched off. " +
|
||||
"In order to enable it provide 'changeManagement/type with one of " +
|
||||
"[${BackendType.values().minus(BackendType.NONE).join(', ')}] and maintain " +
|
||||
"other required properties like 'endpoint', 'credentialsId'."
|
||||
|
@ -216,7 +216,6 @@ public class CommonStepsTest extends BasePiperTest{
|
||||
def stepsWithCallMethodsOtherThanVoid = []
|
||||
|
||||
def whitelist = [
|
||||
'transportRequestCreate',
|
||||
'durationMeasure',
|
||||
]
|
||||
|
||||
|
@ -127,9 +127,9 @@ public class TransportRequestCreateTest extends BasePiperTest {
|
||||
}
|
||||
}
|
||||
|
||||
def transportId = jsr.step.transportRequestCreate(script: nullScript, changeDocumentId: '001', developmentSystemId: '001', cmUtils: cm)
|
||||
jsr.step.transportRequestCreate(script: nullScript, changeDocumentId: '001', developmentSystemId: '001', cmUtils: cm)
|
||||
|
||||
assert transportId == '001'
|
||||
assert nullScript.commonPipelineEnvironment.getTransportRequestId() == '001'
|
||||
assert result == [changeId: '001',
|
||||
developmentSystemId: '001',
|
||||
cmEndpoint: 'https://example.org/cm',
|
||||
@ -166,14 +166,14 @@ public class TransportRequestCreateTest extends BasePiperTest {
|
||||
}
|
||||
}
|
||||
|
||||
def transportId = jsr.step.transportRequestCreate(script: nullScript,
|
||||
transportType: 'W',
|
||||
targetSystem: 'XYZ',
|
||||
description: 'desc',
|
||||
changeManagement: [type: 'CTS'],
|
||||
cmUtils: cm)
|
||||
jsr.step.call(script: nullScript,
|
||||
transportType: 'W',
|
||||
targetSystem: 'XYZ',
|
||||
description: 'desc',
|
||||
changeManagement: [type: 'CTS'],
|
||||
cmUtils: cm)
|
||||
|
||||
assert transportId == '001'
|
||||
assert nullScript.commonPipelineEnvironment.getTransportRequestId() == '001'
|
||||
assert result == [transportType: 'W',
|
||||
targetSystemId: 'XYZ',
|
||||
description: 'desc',
|
||||
|
@ -108,6 +108,10 @@ public class TransportRequestReleaseTest extends BasePiperTest {
|
||||
@Test
|
||||
public void releaseTransportRequestSuccessTest() {
|
||||
|
||||
// Here we test only the case where the transportRequestId is
|
||||
// provided via parameters. The other cases are tested by
|
||||
// corresponding tests for StepHelpers#getTransportRequestId(./.)
|
||||
|
||||
jlr.expect("[INFO] Closing transport request '002' for change document '001'.")
|
||||
jlr.expect("[INFO] Transport Request '002' has been successfully closed.")
|
||||
|
||||
|
@ -194,6 +194,10 @@ public class TransportRequestUploadFileTest extends BasePiperTest {
|
||||
@Test
|
||||
public void uploadFileToTransportRequestSOLMANSuccessTest() {
|
||||
|
||||
// Here we test only the case where the transportRequestId is
|
||||
// provided via parameters. The other cases are tested by
|
||||
// corresponding tests for StepHelpers#getTransportRequestId(./.)
|
||||
|
||||
jlr.expect("[INFO] Uploading file '/path' to transport request '002' of change document '001'.")
|
||||
jlr.expect("[INFO] File '/path' has been successfully uploaded to transport request '002' of change document '001'.")
|
||||
|
||||
|
@ -20,15 +20,18 @@ class StepHelpersTest extends BasePiperTest {
|
||||
to: 'HEAD',
|
||||
format: '%b'
|
||||
],
|
||||
changeDocumentLabel: "ChangeDocument:"
|
||||
changeDocumentLabel: "ChangeDocument:",
|
||||
transportRequestLabel: "TransportRequest:",
|
||||
]
|
||||
]
|
||||
|
||||
private Map getChangeDocumentIdReceivedParameters = [:]
|
||||
private Map getTransportRequestIdReceivedParameters = [:]
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
getChangeDocumentIdReceivedParameters.clear()
|
||||
getTransportRequestIdReceivedParameters.clear()
|
||||
}
|
||||
|
||||
JenkinsLoggingRule jlr = new JenkinsLoggingRule(this)
|
||||
@ -38,6 +41,20 @@ class StepHelpersTest extends BasePiperTest {
|
||||
.around(jlr)
|
||||
|
||||
private ChangeManagement cm = new ChangeManagement(nullScript) {
|
||||
|
||||
String getTransportRequestId(
|
||||
String from,
|
||||
String to,
|
||||
String label,
|
||||
String format
|
||||
) {
|
||||
getTransportRequestIdReceivedParameters['from'] = from
|
||||
getTransportRequestIdReceivedParameters['to'] = to
|
||||
getTransportRequestIdReceivedParameters['label'] = label
|
||||
getTransportRequestIdReceivedParameters['format'] = format
|
||||
return '097'
|
||||
}
|
||||
|
||||
String getChangeDocumentId(
|
||||
String from,
|
||||
String to,
|
||||
@ -53,6 +70,24 @@ class StepHelpersTest extends BasePiperTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void transportRequestIdViaCommitHistoryTest() {
|
||||
|
||||
def transportRequestId = StepHelpers.getTransportRequestId(cm, nullScript, params)
|
||||
|
||||
assert transportRequestId == '097'
|
||||
assert getTransportRequestIdReceivedParameters ==
|
||||
[
|
||||
from: 'HEAD~1',
|
||||
to: 'HEAD',
|
||||
label: 'TransportRequest:',
|
||||
format: '%b'
|
||||
]
|
||||
|
||||
// We cache the value. Otherwise we have to retrieve it each time from the
|
||||
// commit history.
|
||||
assert nullScript.commonPipelineEnvironment.getTransportRequestId() == '097'
|
||||
}
|
||||
|
||||
public void changeDocumentIdViaCommitHistoryTest() {
|
||||
|
||||
def changeDocumentId = StepHelpers.getChangeDocumentId(cm, nullScript, params)
|
||||
@ -69,10 +104,60 @@ class StepHelpersTest extends BasePiperTest {
|
||||
// We cache the value. Otherwise we have to retrieve it each time from the
|
||||
// commit history.
|
||||
assert nullScript.commonPipelineEnvironment.getChangeDocumentId() == '001'
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void transportRequestIdViaCommonPipelineEnvironmentTest() {
|
||||
|
||||
nullScript.commonPipelineEnvironment.setTransportRequestId('098')
|
||||
def transportRequestId = StepHelpers.getTransportRequestId(cm, nullScript, params)
|
||||
|
||||
assert transportRequestId == '098'
|
||||
|
||||
// getTransportRequestId gets not called on ChangeManagement util class
|
||||
// in this case.
|
||||
assert getTransportRequestIdReceivedParameters == [:]
|
||||
}
|
||||
|
||||
@Test
|
||||
public void transportRequestIdViaParametersTest() {
|
||||
|
||||
params << [transportRequestId: '099']
|
||||
|
||||
def transportRequestId = StepHelpers.getTransportRequestId(cm, nullScript, params)
|
||||
|
||||
assert transportRequestId == '099'
|
||||
|
||||
// In case we get the transport request id via parameters we do not cache it
|
||||
// Caller knows the transport request id anyway. So the caller can provide it with
|
||||
// each call.
|
||||
assert nullScript.commonPipelineEnvironment.getTransportRequestId() == null
|
||||
|
||||
// getTransportRequestId gets not called on ChangeManagement util class
|
||||
// in this case.
|
||||
assert getTransportRequestIdReceivedParameters == [:]
|
||||
}
|
||||
|
||||
@Test
|
||||
public void transportRequestIdNotProvidedTest() {
|
||||
|
||||
jlr.expect('Cannot retrieve transportRequestId from commit history')
|
||||
|
||||
def cm = new ChangeManagement(nullScript) {
|
||||
String getTransportRequestId(
|
||||
String from,
|
||||
String to,
|
||||
String label,
|
||||
String format
|
||||
) {
|
||||
throw new ChangeManagementException('Cannot retrieve transport request id')
|
||||
}
|
||||
}
|
||||
|
||||
def transportRequestId = StepHelpers.getTransportRequestId(cm, nullScript, params)
|
||||
assert transportRequestId == null
|
||||
}
|
||||
|
||||
public void changeDocumentIdViaCommonPipelineEnvironmentTest() {
|
||||
|
||||
nullScript.commonPipelineEnvironment.setChangeDocumentId('002')
|
||||
@ -120,8 +205,8 @@ class StepHelpersTest extends BasePiperTest {
|
||||
}
|
||||
}
|
||||
|
||||
def transportRequestId = StepHelpers.getChangeDocumentId(cm, nullScript, params)
|
||||
def changeDocumentId = StepHelpers.getChangeDocumentId(cm, nullScript, params)
|
||||
|
||||
assert transportRequestId == null
|
||||
assert changeDocumentId == null
|
||||
}
|
||||
}
|
||||
|
@ -97,7 +97,7 @@ void call(parameters = [:]) {
|
||||
new Utils().pushToSWA([step: STEP_NAME,
|
||||
stepParam1: parameters?.script == null], configuration)
|
||||
|
||||
def changeId = getChangeDocumentId(cm, this, configuration)
|
||||
def changeId = getChangeDocumentId(cm, script, configuration)
|
||||
|
||||
configuration = configHelper.mixin([changeDocumentId: changeId?.trim() ?: null], ['changeDocumentId'] as Set)
|
||||
|
||||
|
@ -30,6 +30,7 @@ class commonPipelineEnvironment implements Serializable {
|
||||
|
||||
String mtarFilePath
|
||||
|
||||
String transportRequestId
|
||||
String changeDocumentId
|
||||
|
||||
def reset() {
|
||||
@ -52,6 +53,7 @@ class commonPipelineEnvironment implements Serializable {
|
||||
|
||||
mtarFilePath = null
|
||||
|
||||
transportRequestId = null
|
||||
changeDocumentId = null
|
||||
}
|
||||
|
||||
|
@ -190,9 +190,12 @@ void call(parameters = [:]) {
|
||||
"""--user '${username}' \
|
||||
--password '${password}' \
|
||||
"""
|
||||
dockerExecute(dockerImage: configuration.get('dockerImage'),
|
||||
dockerEnvVars: configuration.get('dockerEnvVars'),
|
||||
dockerOptions: configuration.get('dockerOptions')) {
|
||||
dockerExecute(
|
||||
script: script,
|
||||
dockerImage: configuration.get('dockerImage'),
|
||||
dockerEnvVars: configuration.get('dockerEnvVars'),
|
||||
dockerOptions: configuration.get('dockerOptions')
|
||||
) {
|
||||
|
||||
neo.verify(this, configuration)
|
||||
|
||||
|
@ -27,7 +27,7 @@ import hudson.AbortException
|
||||
|
||||
@Field Set PARAMETER_KEYS = STEP_CONFIG_KEYS.plus(['changeDocumentId'])
|
||||
|
||||
def call(parameters = [:]) {
|
||||
void call(parameters = [:]) {
|
||||
|
||||
def transportRequestId
|
||||
|
||||
@ -68,7 +68,7 @@ def call(parameters = [:]) {
|
||||
|
||||
if(backendType == BackendType.SOLMAN) {
|
||||
|
||||
changeDocumentId = getChangeDocumentId(cm, this, configuration)
|
||||
changeDocumentId = getChangeDocumentId(cm, script, configuration)
|
||||
|
||||
configHelper.mixin([changeDocumentId: changeDocumentId?.trim() ?: null], ['changeDocumentId'] as Set)
|
||||
.withMandatoryProperty('developmentSystemId')
|
||||
@ -110,7 +110,6 @@ def call(parameters = [:]) {
|
||||
|
||||
|
||||
echo "[INFO] Transport Request '$transportRequestId' has been successfully created."
|
||||
script.commonPipelineEnvironment.setTransportRequestId(transportRequestId)
|
||||
}
|
||||
|
||||
return transportRequestId
|
||||
}
|
||||
|
@ -62,11 +62,11 @@ void call(parameters = [:]) {
|
||||
stepParam1: parameters?.script == null], configuration)
|
||||
|
||||
def changeDocumentId = null
|
||||
def transportRequestId = getTransportRequestId(cm, this, configuration)
|
||||
def transportRequestId = getTransportRequestId(cm, script, configuration)
|
||||
|
||||
if(backendType == BackendType.SOLMAN) {
|
||||
|
||||
changeDocumentId = getChangeDocumentId(cm, this, configuration)
|
||||
changeDocumentId = getChangeDocumentId(cm, script, configuration)
|
||||
|
||||
configHelper.mixin([changeDocumentId: changeDocumentId?.trim() ?: null], ['changeDocumentId'] as Set)
|
||||
.withMandatoryProperty('changeDocumentId',
|
||||
|
@ -68,10 +68,10 @@ void call(parameters = [:]) {
|
||||
def changeDocumentId = null
|
||||
|
||||
if(backendType == BackendType.SOLMAN) {
|
||||
changeDocumentId = getChangeDocumentId(cm, this, configuration)
|
||||
changeDocumentId = getChangeDocumentId(cm, script, configuration)
|
||||
}
|
||||
|
||||
def transportRequestId = getTransportRequestId(cm, this, configuration)
|
||||
def transportRequestId = getTransportRequestId(cm, script, configuration)
|
||||
|
||||
configHelper
|
||||
.mixin([changeDocumentId: changeDocumentId?.trim() ?: null,
|
||||
|
Loading…
x
Reference in New Issue
Block a user