mirror of
https://github.com/SAP/jenkins-library.git
synced 2024-12-14 11:03:09 +02:00
Merge remote-tracking branch 'github/master' into HEAD
This commit is contained in:
commit
3e01caf909
@ -14,12 +14,20 @@ Creates a Transport Request for a Change Document on the Solution Manager.
|
|||||||
| `credentialsId` | yes | | |
|
| `credentialsId` | yes | | |
|
||||||
| `endpoint` | yes | | |
|
| `endpoint` | yes | | |
|
||||||
| `clientOpts` | no | | |
|
| `clientOpts` | no | | |
|
||||||
|
| `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.
|
* `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 to transport.
|
* `changeDocumentId` - The id of the change document to transport.
|
||||||
* `credentialsId` - The credentials to connect to the Solution Manager.
|
* `credentialsId` - The credentials to connect to the Solution Manager.
|
||||||
* `endpoint` - The address of the Solution Manager.
|
* `endpoint` - The address of the Solution Manager.
|
||||||
* `clientOpts`- Options forwarded to JVM used by the CM client, like `JAVA_OPTS`
|
* `clientOpts`- Options forwarded to JVM used by the CM client, like `JAVA_OPTS`
|
||||||
|
* `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
|
## Step configuration
|
||||||
The following parameters can also be specified as step parameters using the global configuration file:
|
The following parameters can also be specified as step parameters using the global configuration file:
|
||||||
|
@ -16,6 +16,10 @@ Uploads a file to a Transport Request for a Change Document on the Solution Mana
|
|||||||
| `filePath` | yes | | |
|
| `filePath` | yes | | |
|
||||||
| `credentialsId` | yes | | |
|
| `credentialsId` | yes | | |
|
||||||
| `endpoint` | 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.
|
* `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.
|
* `changeDocumentId` - The id of the change document related to the transport request to release.
|
||||||
@ -24,6 +28,10 @@ Uploads a file to a Transport Request for a Change Document on the Solution Mana
|
|||||||
* `filePath` - The path of the file to upload.
|
* `filePath` - The path of the file to upload.
|
||||||
* `credentialsId` - The credentials to connect to the Solution Manager.
|
* `credentialsId` - The credentials to connect to the Solution Manager.
|
||||||
* `endpoint` - The address of 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
|
## Step configuration
|
||||||
The following parameters can also be specified as step parameters using the global configuration file:
|
The following parameters can also be specified as step parameters using the global configuration file:
|
||||||
|
@ -72,13 +72,14 @@ public class ChangeManagement implements Serializable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void uploadFileToTransportRequest(String changeId, String transportRequestId, String applicationId, String filePath, String endpoint, String username, String password) {
|
void uploadFileToTransportRequest(String changeId, String transportRequestId, String applicationId, String filePath, String endpoint, String username, String password, String cmclientOpts = '') {
|
||||||
|
|
||||||
int rc = script.sh(returnStatus: true,
|
int rc = script.sh(returnStatus: true,
|
||||||
script: getCMCommandLine(endpoint, username, password,
|
script: getCMCommandLine(endpoint, username, password,
|
||||||
'upload-file-to-transport', ['-cID', changeId,
|
'upload-file-to-transport', ['-cID', changeId,
|
||||||
'-tID', transportRequestId,
|
'-tID', transportRequestId,
|
||||||
applicationId, filePath]))
|
applicationId, filePath],
|
||||||
|
cmclientOpts))
|
||||||
|
|
||||||
if(rc == 0) {
|
if(rc == 0) {
|
||||||
return
|
return
|
||||||
|
@ -61,10 +61,21 @@ public class TransportRequestCreateTest extends BasePiperTest {
|
|||||||
@Test
|
@Test
|
||||||
public void changeIdNotProvidedTest() {
|
public void changeIdNotProvidedTest() {
|
||||||
|
|
||||||
thrown.expect(AbortException)
|
ChangeManagement cm = new ChangeManagement(nullScript) {
|
||||||
thrown.expectMessage("Change document id not provided (parameter: 'changeDocumentId').")
|
String getChangeDocumentId(
|
||||||
|
String from,
|
||||||
|
String to,
|
||||||
|
String label,
|
||||||
|
String format
|
||||||
|
) {
|
||||||
|
throw new ChangeManagementException('Cannot retrieve changeId from git commits.')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
jsr.step.call(script: nullScript, developmentSystemId: '001')
|
thrown.expect(AbortException)
|
||||||
|
thrown.expectMessage("Change document id not provided (parameter: 'changeDocumentId' or via commit history).")
|
||||||
|
|
||||||
|
jsr.step.call(script: nullScript, developmentSystemId: '001', cmUtils: cm)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -60,10 +60,21 @@ public class TransportRequestUploadFileTest extends BasePiperTest {
|
|||||||
@Test
|
@Test
|
||||||
public void changeDocumentIdNotProvidedTest() {
|
public void changeDocumentIdNotProvidedTest() {
|
||||||
|
|
||||||
thrown.expect(AbortException)
|
ChangeManagement cm = new ChangeManagement(nullScript) {
|
||||||
thrown.expectMessage("Change document id not provided (parameter: 'changeDocumentId').")
|
String getChangeDocumentId(
|
||||||
|
String from,
|
||||||
|
String to,
|
||||||
|
String pattern,
|
||||||
|
String format
|
||||||
|
) {
|
||||||
|
throw new ChangeManagementException('Cannot retrieve changeId from git commits.')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
jsr.step.call(script: nullScript, transportRequestId: '001', applicationId: 'app', filePath: '/path')
|
thrown.expect(AbortException)
|
||||||
|
thrown.expectMessage("Change document id not provided (parameter: 'changeDocumentId' or via commit history).")
|
||||||
|
|
||||||
|
jsr.step.call(script: nullScript, transportRequestId: '001', applicationId: 'app', filePath: '/path', cmUtils: cm)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -103,7 +114,8 @@ public class TransportRequestUploadFileTest extends BasePiperTest {
|
|||||||
String filePath,
|
String filePath,
|
||||||
String endpoint,
|
String endpoint,
|
||||||
String username,
|
String username,
|
||||||
String password) {
|
String password,
|
||||||
|
String cmclientOpts) {
|
||||||
throw new ChangeManagementException('Exception message')
|
throw new ChangeManagementException('Exception message')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,11 @@ import hudson.AbortException
|
|||||||
@Field Set stepConfigurationKeys = [
|
@Field Set stepConfigurationKeys = [
|
||||||
'credentialsId',
|
'credentialsId',
|
||||||
'clientOpts',
|
'clientOpts',
|
||||||
'endpoint'
|
'endpoint',
|
||||||
|
'gitFrom',
|
||||||
|
'gitTo',
|
||||||
|
'gitChangeDocumentLabel',
|
||||||
|
'gitFormat'
|
||||||
]
|
]
|
||||||
|
|
||||||
@Field Set parameterKeys = stepConfigurationKeys.plus(['changeDocumentId', 'developmentSystemId'])
|
@Field Set parameterKeys = stepConfigurationKeys.plus(['changeDocumentId', 'developmentSystemId'])
|
||||||
@ -38,7 +42,33 @@ def call(parameters = [:]) {
|
|||||||
.use()
|
.use()
|
||||||
|
|
||||||
def changeDocumentId = configuration.changeDocumentId
|
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?.trim()) {
|
||||||
|
throw new AbortException("Change document id not provided (parameter: \'changeDocumentId\' or via commit history).")
|
||||||
|
}
|
||||||
|
|
||||||
def developmentSystemId = configuration.developmentSystemId
|
def developmentSystemId = configuration.developmentSystemId
|
||||||
if(!developmentSystemId) throw new AbortException('Development system id not provided (parameter: \'developmentSystemId\').')
|
if(!developmentSystemId) throw new AbortException('Development system id not provided (parameter: \'developmentSystemId\').')
|
||||||
|
@ -13,7 +13,12 @@ import hudson.AbortException
|
|||||||
|
|
||||||
@Field Set generalConfigurationKeys = [
|
@Field Set generalConfigurationKeys = [
|
||||||
'credentialsId',
|
'credentialsId',
|
||||||
'endpoint'
|
'cmClientOpts',
|
||||||
|
'endpoint',
|
||||||
|
'gitFrom',
|
||||||
|
'gitTo',
|
||||||
|
'gitChangeDocumentLabel',
|
||||||
|
'gitFormat'
|
||||||
]
|
]
|
||||||
|
|
||||||
@Field Set parameterKeys = generalConfigurationKeys.plus([
|
@Field Set parameterKeys = generalConfigurationKeys.plus([
|
||||||
@ -41,7 +46,34 @@ def call(parameters = [:]) {
|
|||||||
.use()
|
.use()
|
||||||
|
|
||||||
def changeDocumentId = configuration.changeDocumentId
|
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?.trim()) {
|
||||||
|
throw new AbortException("Change document id not provided (parameter: 'changeDocumentId' or via commit history).")
|
||||||
|
}
|
||||||
|
|
||||||
def transportRequestId = configuration.transportRequestId
|
def transportRequestId = configuration.transportRequestId
|
||||||
if(!transportRequestId) throw new AbortException("Transport Request id not provided (parameter: 'transportRequestId').")
|
if(!transportRequestId) throw new AbortException("Transport Request id not provided (parameter: 'transportRequestId').")
|
||||||
@ -66,7 +98,7 @@ def call(parameters = [:]) {
|
|||||||
usernameVariable: 'username')]) {
|
usernameVariable: 'username')]) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
cm.uploadFileToTransportRequest(changeDocumentId, transportRequestId, applicationId, filePath, endpoint, username, password)
|
cm.uploadFileToTransportRequest(changeDocumentId, transportRequestId, applicationId, filePath, endpoint, username, password, configuration.cmClientOpts)
|
||||||
} catch(ChangeManagementException ex) {
|
} catch(ChangeManagementException ex) {
|
||||||
throw new AbortException(ex.getMessage())
|
throw new AbortException(ex.getMessage())
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user