mirror of
https://github.com/SAP/jenkins-library.git
synced 2025-02-07 13:42:23 +02:00
transportRequestRelease: get changeDocumentId from commit history
This commit is contained in:
parent
4a92f65e66
commit
4a9c0695ca
@ -14,12 +14,20 @@ Releases a Transport Request for a Change Document on the Solution Manager.
|
||||
| `transportRequestId`| yes | | |
|
||||
| `credentialsId` | yes | | |
|
||||
| `endpoint` | yes | | |
|
||||
| `gitFrom` | no | `origin/master` | |
|
||||
| `gitTo` | no | `HEAD` | |
|
||||
| `gitChangeDocumentLabel` | no | `ChangeDocument\s?:` | regex pattern |
|
||||
| `gitFormat` | no | `%b` | see `git log --help` |
|
||||
|
||||
* `script` - The common script environment of the Jenkinsfile running. Typically the reference to the script calling the pipeline step is provided with the `this` parameter, as in `script: this`. This allows the function to access the [`commonPipelineEnvironment`](commonPipelineEnvironment.md) for retrieving, for example, configuration parameters.
|
||||
* `changeDocumentId` - The id of the change document related to the transport request to release.
|
||||
* `transportRequestId` - The id of the transport request to release.
|
||||
* `credentialsId` - The credentials to connect to the Solution Manager.
|
||||
* `endpoint` - The address of the Solution Manager.
|
||||
* `gitFrom` - The starting point for retrieving the change document id
|
||||
* `gitTo` - The end point for retrieving the change document id
|
||||
* `gitChangeDocumentLabel` - A pattern used for identifying lines holding the change document id.
|
||||
* `gitFormat` - Specifies what part of the commit is scanned. By default the body of the commit message is scanned.
|
||||
|
||||
## Step configuration
|
||||
The following parameters can also be specified as step parameters using the global configuration file:
|
||||
|
@ -4,6 +4,9 @@ import org.junit.Test
|
||||
import org.junit.rules.ExpectedException
|
||||
import org.junit.rules.RuleChain
|
||||
|
||||
import com.sap.piper.cm.ChangeManagement
|
||||
import com.sap.piper.cm.ChangeManagementException
|
||||
|
||||
import util.BasePiperTest
|
||||
import util.JenkinsStepRule
|
||||
import util.JenkinsLoggingRule
|
||||
@ -57,10 +60,19 @@ public class TransportRequestReleaseTest extends BasePiperTest {
|
||||
@Test
|
||||
public void changeIdNotProvidedTest() {
|
||||
|
||||
thrown.expect(AbortException)
|
||||
thrown.expectMessage("Change document id not provided (parameter: 'changeDocumentId').")
|
||||
ChangeManagement cm = new ChangeManagement(nullScript) {
|
||||
String getChangeDocumentId(String from,
|
||||
String to,
|
||||
String label,
|
||||
String format) {
|
||||
throw new ChangeManagementException('Cannot retrieve change documentId')
|
||||
}
|
||||
}
|
||||
|
||||
jsr.step.call(script: nullScript, transportRequestId: '001')
|
||||
thrown.expect(AbortException)
|
||||
thrown.expectMessage("Change document id not provided (parameter: 'changeDocumentId' or via commit history).")
|
||||
|
||||
jsr.step.call(script: nullScript, transportRequestId: '001', cmUtils: cm)
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -14,12 +14,20 @@ import hudson.AbortException
|
||||
'changeDocumentId',
|
||||
'transportRequestId',
|
||||
'credentialsId',
|
||||
'endpoint'
|
||||
'endpoint',
|
||||
'gitChangeDocumentLabel',
|
||||
'gitFormat',
|
||||
'gitFrom',
|
||||
'gitTo'
|
||||
]
|
||||
|
||||
@Field Set stepConfigurationKeys = [
|
||||
'credentialsId',
|
||||
'endpoint'
|
||||
'endpoint',
|
||||
'gitChangeDocumentLabel',
|
||||
'gitFormat',
|
||||
'gitFrom',
|
||||
'gitTo'
|
||||
]
|
||||
|
||||
def call(parameters = [:]) {
|
||||
@ -28,14 +36,43 @@ def call(parameters = [:]) {
|
||||
|
||||
def script = parameters?.script ?: [commonPipelineEnvironment: commonPipelineEnvironment]
|
||||
|
||||
ChangeManagement cm = new ChangeManagement(script)
|
||||
ChangeManagement cm = parameters.cmUtils ?: new ChangeManagement(script)
|
||||
|
||||
Map configuration = ConfigurationMerger.merge(script, STEP_NAME,
|
||||
parameters, parameterKeys,
|
||||
stepConfigurationKeys)
|
||||
|
||||
def changeDocumentId = configuration.changeDocumentId
|
||||
if(!changeDocumentId) throw new AbortException("Change document id not provided (parameter: 'changeDocumentId').")
|
||||
|
||||
if(changeDocumentId?.trim()) {
|
||||
|
||||
echo "[INFO] ChangeDocumentId '${changeDocumentId}' retrieved from parameters."
|
||||
|
||||
} else {
|
||||
|
||||
echo "[INFO] Retrieving ChangeDocumentId from commit history [from: ${configuration.gitFrom}, to: ${configuration.gitTo}]." +
|
||||
"Searching for pattern '${configuration.gitChangeDocumentLabel}'. Searching with format '${configuration.gitFormat}'."
|
||||
|
||||
try {
|
||||
changeDocumentId = cm.getChangeDocumentId(
|
||||
configuration.gitFrom,
|
||||
configuration.gitTo,
|
||||
configuration.gitChangeDocumentLabel,
|
||||
configuration.gitFormat
|
||||
)
|
||||
|
||||
echo "[INFO] ChangeDocumentId '${changeDocumentId}' retrieved from commit history"
|
||||
|
||||
} catch(ChangeManagementException ex) {
|
||||
echo "[WARN] Cannot retrieve changeDocumentId from commit history: ${ex.getMessage()}."
|
||||
}
|
||||
}
|
||||
|
||||
if(!changeDocumentId) {
|
||||
throw new AbortException("Change document id not provided (parameter: 'changeDocumentId' or via commit history).")
|
||||
}
|
||||
|
||||
boolean isInDevelopment
|
||||
|
||||
def transportRequestId = configuration.transportRequestId
|
||||
if(!transportRequestId) throw new AbortException("Transport Request id not provided (parameter: 'transportRequestId').")
|
||||
|
Loading…
x
Reference in New Issue
Block a user