UploadFileToTransport: Read transportRequestId from commit history

This commit is contained in:
Marcus Holl committed 2018-07-16 10:28:59 +02:00
1 parent bc13d1d969
commit 7482b58dc2
4 files changed
+48 -6

No files matched your search

@@ -19,6 +19,7 @@ Uploads a file to a Transport Request for a Change Document on the Solution Mana
| `gitFrom` | no | `origin/master` | |
| `gitTo` | no | `HEAD` | |
| `gitChangeDocumentLabel` | no | `ChangeDocument\s?:` | regex pattern |
| `gitTransportRequestLabel` | no | `TransportRequest\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.
@@ -31,6 +32,7 @@ Uploads a file to a Transport Request for a Change Document on the Solution Mana
* `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.
* `gitTransportRequestLabel` - A pattern used for identifying lines holding the transport request id.
* `gitFormat` - Specifies what part of the commit is scanned. By default the body of the commit message is scanned.
## Step configuration
@@ -191,6 +191,7 @@ steps:
gitFrom: 'origin/master'
gitTo: 'HEAD'
gitChangeDocumentLabel: 'ChangeDocument\s?:'
gitTransportRequestLabel: 'TransportRequest\s?:'
gitFormat: '%b'
transportRequestRelease:
credentialsId: 'CM'
@@ -68,7 +68,7 @@ public class TransportRequestUploadFileTest extends BasePiperTest {
String format
) {
throw new ChangeManagementException('Cannot retrieve changeId from git commits.')
}
}
}
thrown.expect(AbortException)
@@ -80,10 +80,21 @@ public class TransportRequestUploadFileTest extends BasePiperTest {
@Test
public void transportRequestIdNotProvidedTest() {
thrown.expect(AbortException)
thrown.expectMessage("Transport Request id not provided (parameter: 'transportRequestId').")
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.')
}
}
jsr.step.call(script: nullScript, changeDocumentId: '001', applicationId: 'app', filePath: '/path')
thrown.expect(AbortException)
thrown.expectMessage("Transport Request id not provided (parameter: 'transportRequestId' or via commit history).")
jsr.step.call(script: nullScript, changeDocumentId: '001', applicationId: 'app', filePath: '/path', cmUtils: cm)
}
@Test
+30 -2
View File
@@ -22,6 +22,7 @@ import hudson.AbortException
'gitFrom',
'gitTo',
'gitChangeDocumentLabel',
'gitTransportRequestLabel',
'gitFormat'
]
@@ -32,6 +33,7 @@ import hudson.AbortException
'gitFrom',
'gitTo',
'gitChangeDocumentLabel',
'gitTransportRequestLabel',
'gitFormat'
]
@@ -79,12 +81,38 @@ def call(parameters = [:]) {
}
}
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.gitFrom}, to: ${configuration.gitTo}]." +
" Searching for pattern '${configuration.gitTransportRequestLabel}'. Searching with format '${configuration.gitFormat}'."
try {
transportRequestId = cm.getTransportRequestId(
configuration.gitFrom,
configuration.gitTo,
configuration.gitTransportRequestLabel,
configuration.gitFormat
)
echo "[INFO] Transport request id '${transportRequestId}' retrieved from commit history"
} catch(ChangeManagementException ex) {
echo "[WARN] Cannot retrieve transportRequestId from commit history: ${ex.getMessage()}."
}
}
if(! changeDocumentId?.trim()) {
throw new AbortException("Change document id not provided (parameter: 'changeDocumentId' or via commit history).")
}
def transportRequestId = configuration.transportRequestId
if(!transportRequestId) throw new AbortException("Transport Request id not provided (parameter: 'transportRequestId').")
if(!transportRequestId?.trim()) throw new AbortException("Transport Request id not provided (parameter: 'transportRequestId' or via commit history).")
def applicationId = configuration.applicationId
if(!applicationId) throw new AbortException("Application id not provided (parameter: 'applicationId').")