1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2024-12-12 10:55:20 +02:00

Merge pull request #317 from marcusholl/pr/condenceCMCoding

condence cm coding
This commit is contained in:
Marcus Holl 2018-11-05 14:51:52 +01:00 committed by GitHub
commit a405e7e82c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 74 additions and 155 deletions

View File

@ -4,6 +4,68 @@ import com.cloudbees.groovy.cps.NonCPS
public class StepHelpers { public class StepHelpers {
@NonCPS
public static def getTransportRequestId(ChangeManagement cm, def step, Map configuration) {
def transportRequestId = configuration.transportRequestId
if(transportRequestId?.trim()) {
step.echo "[INFO] Transport request id '${transportRequestId}' retrieved from parameters."
} 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
}
@NonCPS
public static getChangeDocumentId(ChangeManagement cm, def step, Map configuration) {
def changeDocumentId = configuration.changeDocumentId
if(changeDocumentId?.trim()) {
step.echo "[INFO] ChangeDocumentId '${changeDocumentId}' retrieved from parameters."
} else {
step.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 {
changeDocumentId = cm.getChangeDocumentId(
configuration.changeManagement.git.from,
configuration.changeManagement.git.to,
configuration.changeManagement.changeDocumentLabel,
configuration.changeManagement.git.format
)
step.echo "[INFO] ChangeDocumentId '${changeDocumentId}' retrieved from commit history"
} catch(ChangeManagementException ex) {
step.echo "[WARN] Cannot retrieve changeDocumentId from commit history: ${ex.getMessage()}."
}
}
return changeDocumentId
}
@NonCPS @NonCPS
static BackendType getBackendTypeAndLogInfoIfCMIntegrationDisabled(def step, Map configuration) { static BackendType getBackendTypeAndLogInfoIfCMIntegrationDisabled(def step, Map configuration) {

View File

@ -11,6 +11,7 @@ import com.sap.piper.cm.BackendType
import com.sap.piper.cm.ChangeManagement import com.sap.piper.cm.ChangeManagement
import com.sap.piper.cm.ChangeManagementException import com.sap.piper.cm.ChangeManagementException
import static com.sap.piper.cm.StepHelpers.getChangeDocumentId
import static com.sap.piper.cm.StepHelpers.getBackendTypeAndLogInfoIfCMIntegrationDisabled import static com.sap.piper.cm.StepHelpers.getBackendTypeAndLogInfoIfCMIntegrationDisabled
@Field def STEP_NAME = 'checkChangeInDevelopment' @Field def STEP_NAME = 'checkChangeInDevelopment'
@ -93,37 +94,10 @@ void call(parameters = [:]) {
*/ */
.withMandatoryProperty('changeManagement/endpoint') .withMandatoryProperty('changeManagement/endpoint')
configuration = configHelper.use()
new Utils().pushToSWA([step: STEP_NAME, new Utils().pushToSWA([step: STEP_NAME,
stepParam1: parameters?.script == null], configuration) stepParam1: parameters?.script == null], configuration)
def changeId = configuration.changeDocumentId def changeId = getChangeDocumentId(cm, this, configuration)
if(changeId?.trim()) {
echo "[INFO] ChangeDocumentId retrieved from parameters."
} else {
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 {
changeId = cm.getChangeDocumentId(
configuration.changeManagement.git.from,
configuration.changeManagement.git.to,
configuration.changeManagement.changeDocumentLabel,
configuration.changeManagement.git.format
)
if(changeId?.trim()) {
echo "[INFO] ChangeDocumentId '${changeId}' retrieved from commit history"
}
} catch(ChangeManagementException ex) {
echo "[WARN] Cannot retrieve changeDocumentId from commit history: ${ex.getMessage()}."
}
}
configuration = configHelper.mixin([changeDocumentId: changeId?.trim() ?: null], ['changeDocumentId'] as Set) configuration = configHelper.mixin([changeDocumentId: changeId?.trim() ?: null], ['changeDocumentId'] as Set)
@ -142,7 +116,6 @@ void call(parameters = [:]) {
try { try {
isInDevelopment = cm.isChangeInDevelopment(configuration.changeDocumentId, isInDevelopment = cm.isChangeInDevelopment(configuration.changeDocumentId,
configuration.changeManagement.endpoint, configuration.changeManagement.endpoint,
configuration.changeManagement.credentialsId, configuration.changeManagement.credentialsId,

View File

@ -10,6 +10,7 @@ import com.sap.piper.cm.ChangeManagementException
import static com.sap.piper.cm.StepHelpers.getBackendTypeAndLogInfoIfCMIntegrationDisabled import static com.sap.piper.cm.StepHelpers.getBackendTypeAndLogInfoIfCMIntegrationDisabled
import static com.sap.piper.cm.StepHelpers.getChangeDocumentId
import hudson.AbortException import hudson.AbortException
@Field def STEP_NAME = 'transportRequestCreate' @Field def STEP_NAME = 'transportRequestCreate'
@ -67,31 +68,8 @@ def call(parameters = [:]) {
if(backendType == BackendType.SOLMAN) { if(backendType == BackendType.SOLMAN) {
changeDocumentId = configuration.changeDocumentId changeDocumentId = getChangeDocumentId(cm, this, configuration)
if(changeDocumentId?.trim()) {
echo "[INFO] ChangeDocumentId '${changeDocumentId}' retrieved from parameters."
} else {
echo "[INFO] Retrieving ChangeDocumentId from commit history [from: ${configuration.changeManagement.git.from}, to: ${configuration.changeManagement.git.to}]." +
"Searching for pattern '${configuration.changeDocumentLabel}'. Searching with format '${configuration.changeManagement.git.format}'."
try {
changeDocumentId = cm.getChangeDocumentId(
configuration.changeManagement.git.from,
configuration.changeManagement.git.to,
configuration.changeManagement.changeDocumentLabel,
configuration.changeManagement.git.format
)
echo "[INFO] ChangeDocumentId '${changeDocumentId}' retrieved from commit history"
} catch(ChangeManagementException ex) {
echo "[WARN] Cannot retrieve changeDocumentId from commit history: ${ex.getMessage()}."
}
}
configHelper.mixin([changeDocumentId: changeDocumentId?.trim() ?: null], ['changeDocumentId'] as Set) configHelper.mixin([changeDocumentId: changeDocumentId?.trim() ?: null], ['changeDocumentId'] as Set)
.withMandatoryProperty('developmentSystemId') .withMandatoryProperty('developmentSystemId')
.withMandatoryProperty('changeDocumentId', .withMandatoryProperty('changeDocumentId',

View File

@ -10,6 +10,8 @@ import com.sap.piper.cm.ChangeManagementException
import hudson.AbortException import hudson.AbortException
import static com.sap.piper.cm.StepHelpers.getTransportRequestId
import static com.sap.piper.cm.StepHelpers.getChangeDocumentId
import static com.sap.piper.cm.StepHelpers.getBackendTypeAndLogInfoIfCMIntegrationDisabled import static com.sap.piper.cm.StepHelpers.getBackendTypeAndLogInfoIfCMIntegrationDisabled
@Field def STEP_NAME = 'transportRequestRelease' @Field def STEP_NAME = 'transportRequestRelease'
@ -59,61 +61,12 @@ void call(parameters = [:]) {
new Utils().pushToSWA([step: STEP_NAME, new Utils().pushToSWA([step: STEP_NAME,
stepParam1: parameters?.script == null], configuration) stepParam1: parameters?.script == null], configuration)
def transportRequestId = configuration.transportRequestId
if(transportRequestId?.trim()) {
echo "[INFO] Transport request id '${transportRequestId}' retrieved from parameters."
} else {
echo "[INFO] Retrieving transport request id from commit history [from: ${configuration.changeManagement.git.from}, to: ${configuration.changeManagement.git.to}]." +
" Searching for pattern '${configuration.gitTransportRequestLabel}'. 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
)
echo "[INFO] Transport request id '${transportRequestId}' retrieved from commit history"
} catch(ChangeManagementException ex) {
echo "[WARN] Cannot retrieve transportRequestId from commit history: ${ex.getMessage()}."
}
}
def changeDocumentId = null def changeDocumentId = null
def transportRequestId = getTransportRequestId(cm, this, configuration)
if(backendType == BackendType.SOLMAN) { if(backendType == BackendType.SOLMAN) {
changeDocumentId = configuration.changeDocumentId changeDocumentId = getChangeDocumentId(cm, this, configuration)
if(changeDocumentId?.trim()) {
echo "[INFO] ChangeDocumentId '${changeDocumentId}' retrieved from parameters."
} else {
echo "[INFO] Retrieving ChangeDocumentId from commit history [from: ${configuration.changeManagement.git.from}, to: ${configuration.changeManagement.git.to}]." +
"Searching for pattern '${configuration.changeDocumentLabel}'. Searching with format '${configuration.changeManagement.git.format}'."
try {
changeDocumentId = cm.getChangeDocumentId(
configuration.changeManagement.git.from,
configuration.changeManagement.git.to,
configuration.changeManagement.changeDocumentLabel,
configuration.changeManagement.gitformat
)
echo "[INFO] ChangeDocumentId '${changeDocumentId}' retrieved from commit history"
} catch(ChangeManagementException ex) {
echo "[WARN] Cannot retrieve changeDocumentId from commit history: ${ex.getMessage()}."
}
}
configHelper.mixin([changeDocumentId: changeDocumentId?.trim() ?: null], ['changeDocumentId'] as Set) configHelper.mixin([changeDocumentId: changeDocumentId?.trim() ?: null], ['changeDocumentId'] as Set)
.withMandatoryProperty('changeDocumentId', .withMandatoryProperty('changeDocumentId',

View File

@ -10,6 +10,8 @@ import com.sap.piper.cm.ChangeManagementException
import hudson.AbortException import hudson.AbortException
import static com.sap.piper.cm.StepHelpers.getTransportRequestId
import static com.sap.piper.cm.StepHelpers.getChangeDocumentId
import static com.sap.piper.cm.StepHelpers.getBackendTypeAndLogInfoIfCMIntegrationDisabled import static com.sap.piper.cm.StepHelpers.getBackendTypeAndLogInfoIfCMIntegrationDisabled
@Field def STEP_NAME = 'transportRequestUploadFile' @Field def STEP_NAME = 'transportRequestUploadFile'
@ -66,59 +68,10 @@ void call(parameters = [:]) {
def changeDocumentId = null def changeDocumentId = null
if(backendType == BackendType.SOLMAN) { if(backendType == BackendType.SOLMAN) {
changeDocumentId = getChangeDocumentId(cm, this, configuration)
changeDocumentId = configuration.changeDocumentId
if(changeDocumentId?.trim()) {
echo "[INFO] ChangeDocumentId '${changeDocumentId}' retrieved from parameters."
} else {
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 {
changeDocumentId = cm.getChangeDocumentId(
configuration.changeManagement.git.from,
configuration.changeManagement.git.to,
configuration.changeManagement.changeDocumentLabel,
configuration.changeManagement.git.format
)
echo "[INFO] ChangeDocumentId '${changeDocumentId}' retrieved from commit history"
} catch(ChangeManagementException ex) {
echo "[WARN] Cannot retrieve changeDocumentId from commit history: ${ex.getMessage()}."
}
}
} }
def transportRequestId = configuration.transportRequestId def transportRequestId = getTransportRequestId(cm, this, configuration)
if(transportRequestId?.trim()) {
echo "[INFO] Transport request id '${transportRequestId}' retrieved from parameters."
} else {
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
)
echo "[INFO] Transport request id '${transportRequestId}' retrieved from commit history"
} catch(ChangeManagementException ex) {
echo "[WARN] Cannot retrieve transportRequestId from commit history: ${ex.getMessage()}."
}
}
configHelper configHelper
.mixin([changeDocumentId: changeDocumentId?.trim() ?: null, .mixin([changeDocumentId: changeDocumentId?.trim() ?: null,