mirror of
https://github.com/SAP/jenkins-library.git
synced 2025-01-18 05:18:24 +02:00
Support CMCLIENT_OPTS
needed e.g. for providing a trust store.
This commit is contained in:
parent
5d0ffa3e69
commit
6d943d2005
@ -40,12 +40,13 @@ public class ChangeManagement implements Serializable {
|
||||
return changeIds.get(0)
|
||||
}
|
||||
|
||||
boolean isChangeInDevelopment(String changeId, String endpoint, String username, String password) {
|
||||
boolean isChangeInDevelopment(String changeId, String endpoint, String username, String password, String cmclientOpts = '') {
|
||||
|
||||
int rc = script.sh(returnStatus: true,
|
||||
script: getCMCommandLine(endpoint, username, password,
|
||||
'is-change-in-development', ['-cID', "'${changeId}'",
|
||||
'--return-code']))
|
||||
'--return-code'],
|
||||
cmclientOpts))
|
||||
|
||||
if(rc == 0) {
|
||||
return true
|
||||
@ -97,13 +98,24 @@ public class ChangeManagement implements Serializable {
|
||||
}
|
||||
}
|
||||
|
||||
String getCMCommandLine(String endpoint, String username, String password, String command, List<String> args) {
|
||||
return """#!/bin/bash
|
||||
cmclient -e '$endpoint' \
|
||||
String getCMCommandLine(String endpoint,
|
||||
String username,
|
||||
String password,
|
||||
String command,
|
||||
List<String> args,
|
||||
String cmclientOpts = '') {
|
||||
String cmCommandLine = '#!/bin/bash'
|
||||
if(cmclientOpts) {
|
||||
cmCommandLine += """
|
||||
export CMCLIENT_OPTS="${cmclientOpts}" """
|
||||
}
|
||||
cmCommandLine += """
|
||||
cmclient -e '$endpoint' \
|
||||
-u '$username' \
|
||||
-p '$password' \
|
||||
-t SOLMAN \
|
||||
${command} ${(args as Iterable).join(' ')}
|
||||
"""
|
||||
return cmCommandLine
|
||||
}
|
||||
}
|
||||
|
@ -58,7 +58,8 @@ class CheckChangeInDevelopmentTest extends BasePiperTest {
|
||||
changeId: '001',
|
||||
endpoint: 'https://example.org/cm',
|
||||
userName: 'defaultUser',
|
||||
password: '********'
|
||||
password: '********',
|
||||
cmclientOpts: null
|
||||
]
|
||||
}
|
||||
|
||||
@ -143,11 +144,12 @@ class CheckChangeInDevelopmentTest extends BasePiperTest {
|
||||
return changeDocumentId
|
||||
}
|
||||
|
||||
boolean isChangeInDevelopment(String changeId, String endpoint, String userName, String password) {
|
||||
boolean isChangeInDevelopment(String changeId, String endpoint, String userName, String password, String cmclientOpts) {
|
||||
cmUtilReceivedParams.changeId = changeId
|
||||
cmUtilReceivedParams.endpoint = endpoint
|
||||
cmUtilReceivedParams.userName = userName
|
||||
cmUtilReceivedParams.password = password
|
||||
cmUtilReceivedParams.cmclientOpts = cmclientOpts
|
||||
|
||||
return inDevelopment
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import static org.hamcrest.Matchers.allOf
|
||||
import static org.hamcrest.Matchers.containsString
|
||||
import static org.hamcrest.Matchers.equalTo
|
||||
import static org.hamcrest.Matchers.is
|
||||
import static org.hamcrest.Matchers.not
|
||||
import static org.junit.Assert.assertThat
|
||||
|
||||
import org.hamcrest.Matchers
|
||||
@ -109,7 +110,11 @@ public class ChangeManagementTest extends BasePiperTest {
|
||||
|
||||
script.setReturnValue(JenkinsShellCallRule.Type.REGEX, "cmclient.*is-change-in-development -cID '001'", 3)
|
||||
|
||||
boolean inDevelopment = new ChangeManagement(nullScript, null).isChangeInDevelopment('001', 'endpoint', 'user', 'password')
|
||||
boolean inDevelopment = new ChangeManagement(nullScript, null)
|
||||
.isChangeInDevelopment('001',
|
||||
'endpoint',
|
||||
'user',
|
||||
'password')
|
||||
|
||||
assertThat(inDevelopment, is(equalTo(false)))
|
||||
}
|
||||
@ -126,7 +131,7 @@ public class ChangeManagementTest extends BasePiperTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetCommandLine() {
|
||||
public void testGetCommandLineWithoutCMClientOpts() {
|
||||
String commandLine = new ChangeManagement(nullScript, null)
|
||||
.getCMCommandLine('https://example.org/cm',
|
||||
"me",
|
||||
@ -134,9 +139,24 @@ public class ChangeManagementTest extends BasePiperTest {
|
||||
"the-command",
|
||||
["-key1", "val1", "-key2", "val2"])
|
||||
commandLine = commandLine.replaceAll(' +', " ")
|
||||
assertThat(commandLine, not(containsString("CMCLIENT_OPTS")))
|
||||
assertThat(commandLine, containsString("cmclient -e 'https://example.org/cm' -u 'me' -p 'topSecret' -t SOLMAN the-command -key1 val1 -key2 val2"))
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetCommandLineWithCMClientOpts() {
|
||||
String commandLine = new ChangeManagement(nullScript, null)
|
||||
.getCMCommandLine('https://example.org/cm',
|
||||
"me",
|
||||
"topSecret",
|
||||
"the-command",
|
||||
["-key1", "val1", "-key2", "val2"],
|
||||
'-Djavax.net.debug=all')
|
||||
commandLine = commandLine.replaceAll(' +', " ")
|
||||
assertThat(commandLine, containsString('export CMCLIENT_OPTS="-Djavax.net.debug=all"'))
|
||||
}
|
||||
|
||||
|
||||
private GitUtils gitUtilsMock(boolean insideWorkTree, String[] changeIds) {
|
||||
return new GitUtils() {
|
||||
public boolean insideWorkTree() {
|
||||
|
@ -9,6 +9,7 @@ import com.sap.piper.cm.ChangeManagementException
|
||||
@Field def STEP_NAME = 'checkChangeInDevelopment'
|
||||
|
||||
@Field Set parameterKeys = [
|
||||
'cmClientOpts',
|
||||
'credentialsId',
|
||||
'endpoint',
|
||||
'failIfStatusIsNotInDevelopment',
|
||||
@ -19,6 +20,7 @@ import com.sap.piper.cm.ChangeManagementException
|
||||
]
|
||||
|
||||
@Field Set stepConfigurationKeys = [
|
||||
'cmClientOpts',
|
||||
'credentialsId',
|
||||
'endpoint',
|
||||
'failIfStatusIsNotInDevelopment',
|
||||
@ -74,7 +76,7 @@ def call(parameters = [:]) {
|
||||
usernameVariable: 'username')]) {
|
||||
|
||||
try {
|
||||
isInDevelopment = cm.isChangeInDevelopment(changeId, configuration.endpoint, username, password)
|
||||
isInDevelopment = cm.isChangeInDevelopment(changeId, configuration.endpoint, username, password, configuration.cmClientOpts)
|
||||
} catch(ChangeManagementException ex) {
|
||||
throw new AbortException(ex.getMessage())
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user