mirror of
https://github.com/SAP/jenkins-library.git
synced 2024-11-24 08:32:32 +02:00
Fix injection of download cache parameters (#1605)
- NPMRegistry was always an empty string - MTA did not use npm registry
This commit is contained in:
parent
e6f5544601
commit
3992f17b32
5
src/com/sap/piper/BuildTool.groovy
Normal file
5
src/com/sap/piper/BuildTool.groovy
Normal file
@ -0,0 +1,5 @@
|
||||
package com.sap.piper
|
||||
|
||||
enum BuildTool {
|
||||
MAVEN, NPM, MTA
|
||||
}
|
@ -3,7 +3,7 @@ package com.sap.piper
|
||||
|
||||
class DownloadCacheUtils {
|
||||
|
||||
static Map injectDownloadCacheInMavenParameters(Script script, Map parameters) {
|
||||
static Map injectDownloadCacheInParameters(Script script, Map parameters, BuildTool buildTool) {
|
||||
if (DownloadCacheUtils.isEnabled(script)) {
|
||||
|
||||
if (!parameters.dockerOptions) {
|
||||
@ -18,11 +18,17 @@ class DownloadCacheUtils {
|
||||
}
|
||||
parameters.dockerOptions.add(DownloadCacheUtils.getDockerOptions(script))
|
||||
|
||||
if (parameters.globalSettingsFile) {
|
||||
throw new IllegalArgumentException("You can not specify the parameter globalSettingsFile if the download cache is active")
|
||||
if (buildTool == BuildTool.MAVEN || buildTool == BuildTool.MTA) {
|
||||
if (parameters.globalSettingsFile) {
|
||||
throw new IllegalArgumentException("You can not specify the parameter globalSettingsFile if the download cache is active")
|
||||
}
|
||||
|
||||
parameters.globalSettingsFile = DownloadCacheUtils.getGlobalMavenSettingsForDownloadCache(script)
|
||||
}
|
||||
|
||||
parameters.globalSettingsFile = DownloadCacheUtils.getGlobalMavenSettingsForDownloadCache(script)
|
||||
if (buildTool == BuildTool.NPM || buildTool == buildTool.MTA) {
|
||||
parameters['defaultNpmRegistry'] = DownloadCacheUtils.getNpmRegistryUri(script)
|
||||
}
|
||||
}
|
||||
|
||||
return parameters
|
||||
@ -76,9 +82,10 @@ class DownloadCacheUtils {
|
||||
}
|
||||
|
||||
static String getNpmRegistryUri(Script script) {
|
||||
String npmRegistry = ''
|
||||
script.node('master') {
|
||||
return "http://${script.env.DL_CACHE_HOSTNAME}:8081/repository/npm-proxy/"
|
||||
npmRegistry = "http://${script.env.DL_CACHE_HOSTNAME}:8081/repository/npm-proxy/"
|
||||
}
|
||||
return ""
|
||||
return npmRegistry
|
||||
}
|
||||
}
|
||||
|
@ -1,3 +1,4 @@
|
||||
import com.sap.piper.BuildTool
|
||||
import com.sap.piper.DownloadCacheUtils
|
||||
import org.junit.Before
|
||||
import org.junit.Rule
|
||||
@ -91,13 +92,13 @@ class DownloadCacheUtilsTest extends BasePiperTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void 'injectDownloadCacheInMavenParameters should not change the parameters if dl cache not active'() {
|
||||
Map newParameters = DownloadCacheUtils.injectDownloadCacheInMavenParameters(nullScript, [:])
|
||||
void 'injectDownloadCacheInParameters should not change the parameters if dl cache not active'() {
|
||||
Map newParameters = DownloadCacheUtils.injectDownloadCacheInParameters(nullScript, [:], BuildTool.MAVEN)
|
||||
assertTrue(newParameters.isEmpty())
|
||||
}
|
||||
|
||||
@Test
|
||||
void 'injectDownloadCacheInMavenParameters should set docker options and global settings'() {
|
||||
void 'injectDownloadCacheInParameters should set docker options and global settings for maven'() {
|
||||
nullScript.env.DL_CACHE_HOSTNAME = 'cx-downloadcache'
|
||||
nullScript.env.DL_CACHE_NETWORK = 'cx-network'
|
||||
|
||||
@ -106,13 +107,44 @@ class DownloadCacheUtilsTest extends BasePiperTest {
|
||||
globalSettingsFile: '.pipeline/global_settings.xml'
|
||||
]
|
||||
|
||||
Map actual = DownloadCacheUtils.injectDownloadCacheInMavenParameters(nullScript, [:])
|
||||
Map actual = DownloadCacheUtils.injectDownloadCacheInParameters(nullScript, [:], BuildTool.MAVEN)
|
||||
|
||||
assertEquals(expected, actual)
|
||||
}
|
||||
|
||||
@Test
|
||||
void 'injectDownloadCacheInMavenParameters should append docker options'() {
|
||||
void 'injectDownloadCacheInParameters should set docker options, global settings and npm default registry for mta'() {
|
||||
nullScript.env.DL_CACHE_HOSTNAME = 'cx-downloadcache'
|
||||
nullScript.env.DL_CACHE_NETWORK = 'cx-network'
|
||||
|
||||
Map expected = [
|
||||
dockerOptions: ['--network=cx-network'],
|
||||
globalSettingsFile: '.pipeline/global_settings.xml',
|
||||
defaultNpmRegistry: 'http://cx-downloadcache:8081/repository/npm-proxy/'
|
||||
]
|
||||
|
||||
Map actual = DownloadCacheUtils.injectDownloadCacheInParameters(nullScript, [:], BuildTool.MTA)
|
||||
|
||||
assertEquals(expected, actual)
|
||||
}
|
||||
|
||||
@Test
|
||||
void 'injectDownloadCacheInParameters should set docker options and default npm config for npm'() {
|
||||
nullScript.env.DL_CACHE_HOSTNAME = 'cx-downloadcache'
|
||||
nullScript.env.DL_CACHE_NETWORK = 'cx-network'
|
||||
|
||||
Map expected = [
|
||||
dockerOptions: ['--network=cx-network'],
|
||||
defaultNpmRegistry: 'http://cx-downloadcache:8081/repository/npm-proxy/'
|
||||
]
|
||||
|
||||
Map actual = DownloadCacheUtils.injectDownloadCacheInParameters(nullScript, [:], BuildTool.NPM)
|
||||
|
||||
assertEquals(expected, actual)
|
||||
}
|
||||
|
||||
@Test
|
||||
void 'injectDownloadCacheInParameters should append docker options'() {
|
||||
nullScript.env.DL_CACHE_HOSTNAME = 'cx-downloadcache'
|
||||
nullScript.env.DL_CACHE_NETWORK = 'cx-network'
|
||||
|
||||
@ -120,7 +152,7 @@ class DownloadCacheUtilsTest extends BasePiperTest {
|
||||
|
||||
|
||||
|
||||
Map actual = DownloadCacheUtils.injectDownloadCacheInMavenParameters(nullScript, [dockerOptions: '--test'])
|
||||
Map actual = DownloadCacheUtils.injectDownloadCacheInParameters(nullScript, [dockerOptions: '--test'], BuildTool.MAVEN)
|
||||
|
||||
assertEquals(expectedDockerOptions, actual.dockerOptions)
|
||||
}
|
||||
|
@ -1,3 +1,4 @@
|
||||
import com.sap.piper.BuildTool
|
||||
import com.sap.piper.DownloadCacheUtils
|
||||
import groovy.transform.Field
|
||||
|
||||
@ -13,6 +14,6 @@ void call(Map parameters = [:]) {
|
||||
[type: 'ssh', id: 'gitSshKeyCredentialsId'],
|
||||
[type: 'usernamePassword', id: 'gitHttpsCredentialsId', env: ['PIPER_username', 'PIPER_password']],
|
||||
]
|
||||
parameters = DownloadCacheUtils.injectDownloadCacheInMavenParameters(script, parameters)
|
||||
parameters = DownloadCacheUtils.injectDownloadCacheInParameters(script, parameters, BuildTool.MAVEN)
|
||||
piperExecuteBin(parameters, STEP_NAME, METADATA_FILE, credentials, false, false, true)
|
||||
}
|
||||
|
@ -1,3 +1,4 @@
|
||||
import com.sap.piper.BuildTool
|
||||
import com.sap.piper.DownloadCacheUtils
|
||||
import groovy.transform.Field
|
||||
|
||||
@ -10,7 +11,7 @@ import static com.sap.piper.Prerequisites.checkScript
|
||||
|
||||
void call(Map parameters = [:]) {
|
||||
final script = checkScript(this, parameters) ?: this
|
||||
parameters = DownloadCacheUtils.injectDownloadCacheInMavenParameters(script, parameters)
|
||||
parameters = DownloadCacheUtils.injectDownloadCacheInParameters(script, parameters, BuildTool.MAVEN)
|
||||
|
||||
List credentials = [[type: 'token', id: 'fortifyCredentialsId', env: ['PIPER_authToken']]]
|
||||
piperExecuteBin(parameters, STEP_NAME, METADATA_FILE, credentials)
|
||||
|
@ -1,3 +1,4 @@
|
||||
import com.sap.piper.BuildTool
|
||||
import com.sap.piper.DownloadCacheUtils
|
||||
import groovy.transform.Field
|
||||
|
||||
@ -9,7 +10,7 @@ import static com.sap.piper.Prerequisites.checkScript
|
||||
void call(Map parameters = [:]) {
|
||||
List credentials = [ ]
|
||||
final script = checkScript(this, parameters) ?: this
|
||||
parameters = DownloadCacheUtils.injectDownloadCacheInMavenParameters(script, parameters)
|
||||
parameters = DownloadCacheUtils.injectDownloadCacheInParameters(script, parameters, BuildTool.MAVEN)
|
||||
|
||||
piperExecuteBin(parameters, STEP_NAME, METADATA_FILE, credentials)
|
||||
}
|
||||
|
@ -1,3 +1,4 @@
|
||||
import com.sap.piper.BuildTool
|
||||
import com.sap.piper.DownloadCacheUtils
|
||||
import com.sap.piper.BashUtils
|
||||
import groovy.transform.Field
|
||||
@ -8,7 +9,7 @@ import static com.sap.piper.Prerequisites.checkScript
|
||||
|
||||
def call(Map parameters = [:]) {
|
||||
final script = checkScript(this, parameters) ?: this
|
||||
parameters = DownloadCacheUtils.injectDownloadCacheInMavenParameters(script, parameters)
|
||||
parameters = DownloadCacheUtils.injectDownloadCacheInParameters(script, parameters, BuildTool.MAVEN)
|
||||
|
||||
validateParameter(parameters.defines, 'defines')
|
||||
validateParameter(parameters.flags, 'flags')
|
||||
|
@ -1,3 +1,4 @@
|
||||
import com.sap.piper.BuildTool
|
||||
import com.sap.piper.ConfigurationLoader
|
||||
import com.sap.piper.DownloadCacheUtils
|
||||
import com.sap.piper.QualityCheck
|
||||
@ -12,7 +13,7 @@ import static com.sap.piper.Prerequisites.checkScript
|
||||
void call(Map parameters = [:]) {
|
||||
final script = checkScript(this, parameters) ?: null
|
||||
List credentials = []
|
||||
parameters = DownloadCacheUtils.injectDownloadCacheInMavenParameters(script, parameters)
|
||||
parameters = DownloadCacheUtils.injectDownloadCacheInParameters(script, parameters, BuildTool.MAVEN)
|
||||
|
||||
try {
|
||||
piperExecuteBin(parameters, STEP_NAME, METADATA_FILE, credentials)
|
||||
|
@ -1,3 +1,4 @@
|
||||
import com.sap.piper.BuildTool
|
||||
import groovy.transform.Field
|
||||
import static com.sap.piper.Prerequisites.checkScript
|
||||
import com.sap.piper.DownloadCacheUtils
|
||||
@ -7,7 +8,7 @@ import com.sap.piper.DownloadCacheUtils
|
||||
|
||||
void call(Map parameters = [:]) {
|
||||
final script = checkScript(this, parameters) ?: this
|
||||
parameters = DownloadCacheUtils.injectDownloadCacheInMavenParameters(script, parameters)
|
||||
parameters = DownloadCacheUtils.injectDownloadCacheInParameters(script, parameters, BuildTool.MTA)
|
||||
|
||||
piperExecuteBin(parameters, STEP_NAME, METADATA_FILE, [])
|
||||
}
|
||||
|
@ -1,3 +1,4 @@
|
||||
import com.sap.piper.BuildTool
|
||||
import com.sap.piper.DownloadCacheUtils
|
||||
import groovy.transform.Field
|
||||
|
||||
@ -10,7 +11,7 @@ import static com.sap.piper.Prerequisites.checkScript
|
||||
|
||||
void call(Map parameters = [:]) {
|
||||
final script = checkScript(this, parameters) ?: this
|
||||
parameters = DownloadCacheUtils.injectDownloadCacheInMavenParameters(script, parameters)
|
||||
parameters = DownloadCacheUtils.injectDownloadCacheInParameters(script, parameters, BuildTool.MAVEN)
|
||||
|
||||
List credentials = [[type: 'usernamePassword', id: 'nexusCredentialsId', env: ['PIPER_user', 'PIPER_password']]]
|
||||
piperExecuteBin(parameters, STEP_NAME, METADATA_FILE, credentials)
|
||||
|
@ -1,3 +1,4 @@
|
||||
import com.sap.piper.BuildTool
|
||||
import com.sap.piper.DownloadCacheUtils
|
||||
import groovy.transform.Field
|
||||
|
||||
@ -14,10 +15,6 @@ void call(Map parameters = [:]) {
|
||||
|
||||
// No credentials required/supported as of now
|
||||
List credentials = []
|
||||
|
||||
parameters['dockerOptions'] = DownloadCacheUtils.getDockerOptions(script)
|
||||
if (DownloadCacheUtils.isEnabled(script)) {
|
||||
parameters['defaultNpmRegistry'] = DownloadCacheUtils.getNpmRegistryUri(script)
|
||||
}
|
||||
parameters = DownloadCacheUtils.injectDownloadCacheInParameters(script, parameters, BuildTool.NPM)
|
||||
piperExecuteBin(parameters, STEP_NAME, METADATA_FILE, credentials)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user