mirror of
https://github.com/SAP/jenkins-library.git
synced 2025-01-18 05:18:24 +02:00
Provide method for retrieving changeDocumentId from config or via git commits.
This commit is contained in:
parent
6d943d2005
commit
7eba5b6915
@ -1,5 +1,7 @@
|
||||
package com.sap.piper.cm
|
||||
|
||||
import java.util.Map
|
||||
|
||||
import com.sap.piper.GitUtils
|
||||
|
||||
import hudson.AbortException
|
||||
@ -15,6 +17,25 @@ public class ChangeManagement implements Serializable {
|
||||
this.gitUtils = gitUtils ?: new GitUtils()
|
||||
}
|
||||
|
||||
String getChangeDocumentId(Map config) {
|
||||
|
||||
if(config.changeDocumentId) {
|
||||
script.echo "[INFO] Use changeDocumentId ${config.changeDocumentId} from configuration."
|
||||
return config.changeDocumentId
|
||||
}
|
||||
|
||||
script.echo "[INFO] Retrieving changeDocumentId from git commit(s) [FROM: ${config.git_from}, TO: ${config.git_to}]"
|
||||
def changeDocumentId = getChangeDocumentId(
|
||||
config.git_from,
|
||||
config.git_to,
|
||||
config.git_label,
|
||||
config.git_format
|
||||
)
|
||||
script.echo "[INFO] ChangeDocumentId retrieved from git commit(s): ${changeDocumentId}."
|
||||
|
||||
return changeDocumentId
|
||||
}
|
||||
|
||||
String getChangeDocumentId(
|
||||
String from = 'origin/master',
|
||||
String to = 'HEAD',
|
||||
|
@ -9,6 +9,7 @@ import com.sap.piper.cm.ChangeManagementException
|
||||
@Field def STEP_NAME = 'checkChangeInDevelopment'
|
||||
|
||||
@Field Set parameterKeys = [
|
||||
'changeDocumentId',
|
||||
'cmClientOpts',
|
||||
'credentialsId',
|
||||
'endpoint',
|
||||
@ -20,6 +21,7 @@ import com.sap.piper.cm.ChangeManagementException
|
||||
]
|
||||
|
||||
@Field Set stepConfigurationKeys = [
|
||||
'changeDocumentId',
|
||||
'cmClientOpts',
|
||||
'credentialsId',
|
||||
'endpoint',
|
||||
@ -48,12 +50,8 @@ def call(parameters = [:]) {
|
||||
def changeId
|
||||
|
||||
try {
|
||||
changeId = cm.getChangeDocumentId(
|
||||
configuration.git_from,
|
||||
configuration.git_to,
|
||||
configuration.git_label,
|
||||
configuration.git_format
|
||||
)
|
||||
|
||||
changeId = cm.getChangeDocumentId(configuration)
|
||||
|
||||
if(! changeId?.trim()) {
|
||||
throw new ChangeManagementException("ChangeId is null or empty.")
|
||||
@ -62,10 +60,6 @@ def call(parameters = [:]) {
|
||||
throw new AbortException(ex.getMessage())
|
||||
}
|
||||
|
||||
echo "[INFO] ChangeId retrieved from git commit(s): '${changeId}'. " +
|
||||
"Commit range: '${configuration.git_from}..${configuration.git_to}'. " +
|
||||
"Searching for label '${configuration.git_label}'."
|
||||
|
||||
boolean isInDevelopment
|
||||
|
||||
echo "[INFO] Checking if change document '$changeId' is in development."
|
||||
|
Loading…
Reference in New Issue
Block a user