1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2024-12-14 11:03:09 +02:00

Handle parameters as env vars instead of options for RFC upload

options are not supported for dockerExecuteOnKubernetes, but
environment variables are. Hence we switch to environment variables
which works on both, plain docker and on kubernetes.

Using env vars is the cleaner approach anyway.
This commit is contained in:
Marcus Holl 2019-02-08 10:45:44 +01:00
parent 8d1786fa8d
commit fe147eff81
2 changed files with 52 additions and 47 deletions

View File

@ -111,11 +111,11 @@ public class ChangeManagement implements Serializable {
String description) {
def command = 'cts createTransportRequest'
List args = [
"--env TRANSPORT_DESCRIPTION=${description}",
"--env ABAP_DEVELOPMENT_INSTANCE=${developmentInstance}",
"--env ABAP_DEVELOPMENT_CLIENT=${developmentClient}",
]
def args = [
TRANSPORT_DESCRIPTION: description,
ABAP_DEVELOPMENT_INSTANCE: developmentInstance,
ABAP_DEVELOPMENT_CLIENT: developmentClient,
]
try {
@ -212,12 +212,12 @@ public class ChangeManagement implements Serializable {
String abapPackage) {
def args = [
"--env ABAP_DEVELOPMENT_INSTANCE=${developmentInstance}",
"--env ABAP_DEVELOPMENT_CLIENT=${developmentClient}",
"--env ABAP_APPLICATION_NAME=${applicationName}",
"--env ABAP_APPLICATION_DESC=${applicationDescription}",
"--env ABAP_PACKAGE=${abapPackage}",
"--env ZIP_FILE_URL=${filePath}",
ABAP_DEVELOPMENT_INSTANCE: developmentInstance,
ABAP_DEVELOPMENT_CLIENT: developmentClient,
ABAP_APPLICATION_NAME: applicationName,
ABAP_APPLICATION_DESC: applicationDescription,
ABAP_PACKAGE: abapPackage,
ZIP_FILE_URL: filePath,
]
int rc = executeWithCredentials(
@ -242,7 +242,7 @@ public class ChangeManagement implements Serializable {
String endpoint,
String credentialsId,
String command,
List args,
def args,
boolean returnStdout = false,
String clientOpts = '') {
@ -265,21 +265,24 @@ public class ChangeManagement implements Serializable {
case BackendType.RFC:
if(! (args in Map)) {
throw new IllegalArgumentException("args expected as Map for backend types ${[BackendType.RFC]}")
}
shArgs.script = command
args = args.plus([
"--env ABAP_DEVELOPMENT_SERVER=${endpoint}",
"--env ABAP_DEVELOPMENT_USER=${script.username}",
"--env ABAP_DEVELOPMENT_PASSWORD=${script.password}"])
dockerOptions = dockerOptions.plus(args)
ABAP_DEVELOPMENT_SERVER: endpoint,
ABAP_DEVELOPMENT_USER: script.username,
ABAP_DEVELOPMENT_PASSWORD: script.password,
])
// user and password are masked by withCredentials
script.echo """[INFO] Executing command line: "${shArgs.script}"."""
script.dockerExecute(script: script,
dockerImage: dockerImage,
dockerOptions: dockerOptions ) {
dockerEnvVars: args ) {
result = script.sh(shArgs)
@ -290,6 +293,9 @@ public class ChangeManagement implements Serializable {
case BackendType.SOLMAN:
case BackendType.CTS:
if(! (args in Collection))
throw new IllegalArgumentException("args expected as Collection for backend types ${[BackendType.SOLMAN, BackendType.CTS]}")
shArgs.script = getCMCommandLine(type, endpoint, script.username, script.password,
command, args,
clientOpts)
@ -374,8 +380,9 @@ public class ChangeManagement implements Serializable {
def cmd = "cts releaseTransport:${transportRequestId}"
def args = [
"--env ABAP_DEVELOPMENT_INSTANCE=${developmentInstance}",
"--env ABAP_DEVELOPMENT_CLIENT=${developmentClient}"]
ABAP_DEVELOPMENT_INSTANCE: developmentInstance,
ABAP_DEVELOPMENT_CLIENT: developmentClient,
]
int rc = executeWithCredentials(
BackendType.RFC,

View File

@ -188,13 +188,13 @@ public void testGetCommandLineWithCMClientOpts() {
assert dockerExecuteRule.dockerParams.dockerImage == 'rfc'
assert dockerExecuteRule.dockerParams.dockerOptions == [
'--env TRANSPORT_DESCRIPTION=Lorem ipsum',
'--env ABAP_DEVELOPMENT_INSTANCE=001',
'--env ABAP_DEVELOPMENT_CLIENT=01',
'--env ABAP_DEVELOPMENT_SERVER=https://example.org/rfc',
'--env ABAP_DEVELOPMENT_USER=user',
'--env ABAP_DEVELOPMENT_PASSWORD=password'
assert dockerExecuteRule.dockerParams.dockerEnvVars == [
TRANSPORT_DESCRIPTION: 'Lorem ipsum',
ABAP_DEVELOPMENT_INSTANCE: '001',
ABAP_DEVELOPMENT_CLIENT: '01',
ABAP_DEVELOPMENT_SERVER: 'https://example.org/rfc',
ABAP_DEVELOPMENT_USER: 'user',
ABAP_DEVELOPMENT_PASSWORD: 'password',
]
assert transportRequestId == 'XYZK9000004'
@ -292,17 +292,17 @@ public void testGetCommandLineWithCMClientOpts() {
assert dockerExecuteRule.dockerParams.dockerImage == 'rfc'
assert dockerExecuteRule.dockerParams.dockerOptions ==
assert dockerExecuteRule.dockerParams.dockerEnvVars ==
[
'--env ABAP_DEVELOPMENT_INSTANCE=01',
'--env ABAP_DEVELOPMENT_CLIENT=00',
'--env ABAP_APPLICATION_NAME=001',
'--env ABAP_APPLICATION_DESC=Lorem ipsum',
'--env ABAP_PACKAGE=XYZ',
'--env ZIP_FILE_URL=https://example.org/mypath/deployArtifact.zip',
'--env ABAP_DEVELOPMENT_SERVER=https://example.org/rfc',
'--env ABAP_DEVELOPMENT_USER=user',
'--env ABAP_DEVELOPMENT_PASSWORD=password',
ABAP_DEVELOPMENT_INSTANCE: '01',
ABAP_DEVELOPMENT_CLIENT: '00',
ABAP_APPLICATION_NAME: '001',
ABAP_APPLICATION_DESC: 'Lorem ipsum',
ABAP_PACKAGE: 'XYZ',
ZIP_FILE_URL: 'https://example.org/mypath/deployArtifact.zip',
ABAP_DEVELOPMENT_SERVER: 'https://example.org/rfc',
ABAP_DEVELOPMENT_USER: 'user',
ABAP_DEVELOPMENT_PASSWORD: 'password',
]
assertThat(script.shell, contains('cts uploadToABAP:002'))
@ -394,16 +394,14 @@ public void testGetCommandLineWithCMClientOpts() {
'001',
'me')
List stringDockerOptions = []
for(item in dockerExecuteRule.dockerParams.dockerOptions)
{
stringDockerOptions = stringDockerOptions.plus([item.toString()])
}
assertThat(stringDockerOptions, hasItem('--env ABAP_DEVELOPMENT_SERVER=https://example.org'))
assertThat(stringDockerOptions, hasItem('--env ABAP_DEVELOPMENT_USER=user'))
assertThat(stringDockerOptions, hasItem('--env ABAP_DEVELOPMENT_PASSWORD=password'))
assertThat(stringDockerOptions, hasItem('--env ABAP_DEVELOPMENT_CLIENT=001'))
assertThat(stringDockerOptions, hasItem('--env ABAP_DEVELOPMENT_INSTANCE=002'))
assert dockerExecuteRule.dockerParams.dockerEnvVars == [
ABAP_DEVELOPMENT_SERVER: 'https://example.org',
ABAP_DEVELOPMENT_USER: 'user',
ABAP_DEVELOPMENT_PASSWORD: 'password',
ABAP_DEVELOPMENT_CLIENT: '001',
ABAP_DEVELOPMENT_INSTANCE: '002',
]
assertThat(script.shell, hasItem('cts releaseTransport:002'))
}