mirror of
https://github.com/SAP/jenkins-library.git
synced 2025-01-08 04:21:26 +02:00
Use go-based npmExecuteScripts, mavenBuild in buildExecute (#1622)
This commit is contained in:
parent
285537f6a4
commit
c490ce9211
@ -340,6 +340,9 @@ steps:
|
|||||||
mavenExecute:
|
mavenExecute:
|
||||||
dockerImage: 'maven:3.5-jdk-7'
|
dockerImage: 'maven:3.5-jdk-7'
|
||||||
logSuccessfulMavenTransfers: false
|
logSuccessfulMavenTransfers: false
|
||||||
|
buildExecute:
|
||||||
|
npmInstall: true
|
||||||
|
npmRunScripts: []
|
||||||
mtaBuild:
|
mtaBuild:
|
||||||
buildTarget: 'NEO'
|
buildTarget: 'NEO'
|
||||||
mtaBuildTool: cloudMbt
|
mtaBuildTool: cloudMbt
|
||||||
|
@ -15,7 +15,10 @@ import static org.hamcrest.CoreMatchers.containsString
|
|||||||
import static org.hamcrest.CoreMatchers.hasItem
|
import static org.hamcrest.CoreMatchers.hasItem
|
||||||
import static org.hamcrest.CoreMatchers.is
|
import static org.hamcrest.CoreMatchers.is
|
||||||
import static org.hamcrest.CoreMatchers.nullValue
|
import static org.hamcrest.CoreMatchers.nullValue
|
||||||
|
import static org.junit.Assert.assertEquals
|
||||||
|
import static org.junit.Assert.assertFalse
|
||||||
import static org.junit.Assert.assertThat
|
import static org.junit.Assert.assertThat
|
||||||
|
import static org.junit.Assert.assertTrue
|
||||||
|
|
||||||
class BuildExecuteTest extends BasePiperTest {
|
class BuildExecuteTest extends BasePiperTest {
|
||||||
private ExpectedException exception = ExpectedException.none()
|
private ExpectedException exception = ExpectedException.none()
|
||||||
@ -37,6 +40,7 @@ class BuildExecuteTest extends BasePiperTest {
|
|||||||
DockerMock(name) {
|
DockerMock(name) {
|
||||||
dockerMockArgs.name = name
|
dockerMockArgs.name = name
|
||||||
}
|
}
|
||||||
|
|
||||||
def build(image, options) {
|
def build(image, options) {
|
||||||
return [image: image, options: options]
|
return [image: image, options: options]
|
||||||
}
|
}
|
||||||
@ -67,16 +71,25 @@ class BuildExecuteTest extends BasePiperTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testMaven() {
|
void testMaven() {
|
||||||
def buildToolCalled = false
|
boolean buildToolCalled = false
|
||||||
helper.registerAllowedMethod('mavenExecute', [Map.class], {m ->
|
boolean installOptionSet = false
|
||||||
|
helper.registerAllowedMethod('mavenBuild', [Map.class], { m ->
|
||||||
buildToolCalled = true
|
buildToolCalled = true
|
||||||
return
|
return
|
||||||
})
|
})
|
||||||
|
helper.registerAllowedMethod('npmExecuteScripts', [Map.class], { m ->
|
||||||
|
installOptionSet = m['install']
|
||||||
|
return
|
||||||
|
})
|
||||||
|
helper.registerAllowedMethod('fileExists', [String.class], { s ->
|
||||||
|
return s == 'package.json'
|
||||||
|
})
|
||||||
stepRule.step.buildExecute(
|
stepRule.step.buildExecute(
|
||||||
script: nullScript,
|
script: nullScript,
|
||||||
buildTool: 'maven',
|
buildTool: 'maven',
|
||||||
)
|
)
|
||||||
assertThat(buildToolCalled, is(true))
|
assertTrue(buildToolCalled)
|
||||||
|
assertTrue(installOptionSet)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -96,7 +109,7 @@ class BuildExecuteTest extends BasePiperTest {
|
|||||||
@Test
|
@Test
|
||||||
void testNpm() {
|
void testNpm() {
|
||||||
def buildToolCalled = false
|
def buildToolCalled = false
|
||||||
helper.registerAllowedMethod('npmExecute', [Map.class], {m ->
|
helper.registerAllowedMethod('npmExecuteScripts', [Map.class], { m ->
|
||||||
buildToolCalled = true
|
buildToolCalled = true
|
||||||
return
|
return
|
||||||
})
|
})
|
||||||
@ -107,6 +120,51 @@ class BuildExecuteTest extends BasePiperTest {
|
|||||||
assertThat(buildToolCalled, is(true))
|
assertThat(buildToolCalled, is(true))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testNpmWithScripts() {
|
||||||
|
boolean actualValue = false
|
||||||
|
helper.registerAllowedMethod('npmExecuteScripts', [Map.class], { m ->
|
||||||
|
actualValue = (m['runScripts'][0] == 'foo' && m['runScripts'][1] == 'bar')
|
||||||
|
return
|
||||||
|
})
|
||||||
|
stepRule.step.buildExecute(
|
||||||
|
script: nullScript,
|
||||||
|
buildTool: 'npm',
|
||||||
|
npmRunScripts: ['foo', 'bar']
|
||||||
|
)
|
||||||
|
assertTrue(actualValue)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testNpmWithInstallFalse() {
|
||||||
|
boolean actualValue = true
|
||||||
|
helper.registerAllowedMethod('npmExecuteScripts', [Map.class], { m ->
|
||||||
|
actualValue = m['install']
|
||||||
|
return
|
||||||
|
})
|
||||||
|
stepRule.step.buildExecute(
|
||||||
|
script: nullScript,
|
||||||
|
buildTool: 'npm',
|
||||||
|
npmInstall: false
|
||||||
|
)
|
||||||
|
assertFalse(actualValue)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testNpmWithInstallTrue() {
|
||||||
|
boolean actualValue = false
|
||||||
|
helper.registerAllowedMethod('npmExecuteScripts', [Map.class], { m ->
|
||||||
|
actualValue = m['install']
|
||||||
|
return
|
||||||
|
})
|
||||||
|
stepRule.step.buildExecute(
|
||||||
|
script: nullScript,
|
||||||
|
buildTool: 'npm',
|
||||||
|
npmInstall: true
|
||||||
|
)
|
||||||
|
assertTrue(actualValue)
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testDocker() {
|
void testDocker() {
|
||||||
binding.setVariable('docker', new DockerMock('test'))
|
binding.setVariable('docker', new DockerMock('test'))
|
||||||
|
@ -3,7 +3,6 @@ import com.sap.piper.GenerateDocumentation
|
|||||||
import com.sap.piper.Utils
|
import com.sap.piper.Utils
|
||||||
import com.sap.piper.ConfigurationHelper
|
import com.sap.piper.ConfigurationHelper
|
||||||
|
|
||||||
import groovy.text.GStringTemplateEngine
|
|
||||||
import groovy.transform.Field
|
import groovy.transform.Field
|
||||||
|
|
||||||
import static com.sap.piper.Prerequisites.checkScript
|
import static com.sap.piper.Prerequisites.checkScript
|
||||||
@ -22,7 +21,7 @@ import static com.sap.piper.Prerequisites.checkScript
|
|||||||
]
|
]
|
||||||
@Field Set STEP_CONFIG_KEYS = GENERAL_CONFIG_KEYS.plus([
|
@Field Set STEP_CONFIG_KEYS = GENERAL_CONFIG_KEYS.plus([
|
||||||
|
|
||||||
/** Only for Docker builds on the local deamon: Defines the build options for the build.*/
|
/** Only for Docker builds on the local daemon: Defines the build options for the build.*/
|
||||||
'containerBuildOptions',
|
'containerBuildOptions',
|
||||||
/** For custom build types: Defines the command to be executed within the `dockerImage` in order to execute the build. */
|
/** For custom build types: Defines the command to be executed within the `dockerImage` in order to execute the build. */
|
||||||
'dockerCommand',
|
'dockerCommand',
|
||||||
@ -30,6 +29,10 @@ import static com.sap.piper.Prerequisites.checkScript
|
|||||||
'dockerImage',
|
'dockerImage',
|
||||||
/** For Docker builds only (mandatory): tag of the image to be built. */
|
/** For Docker builds only (mandatory): tag of the image to be built. */
|
||||||
'dockerImageTag',
|
'dockerImageTag',
|
||||||
|
/** For buildTool npm: Execute npm install (boolean, default 'true') */
|
||||||
|
'npmInstall',
|
||||||
|
/** For buildTool npm: List of npm run scripts to execute */
|
||||||
|
'npmRunScripts'
|
||||||
])
|
])
|
||||||
@Field Set PARAMETER_KEYS = STEP_CONFIG_KEYS
|
@Field Set PARAMETER_KEYS = STEP_CONFIG_KEYS
|
||||||
|
|
||||||
@ -68,13 +71,17 @@ void call(Map parameters = [:]) {
|
|||||||
|
|
||||||
switch(config.buildTool){
|
switch(config.buildTool){
|
||||||
case 'maven':
|
case 'maven':
|
||||||
mavenExecute script: script
|
mavenBuild script: script
|
||||||
|
// in case node_modules exists we assume npm install was executed by maven clean install
|
||||||
|
if (fileExists('package.json') && !fileExists('node_modules')) {
|
||||||
|
npmExecuteScripts script: script, install: true
|
||||||
|
}
|
||||||
break
|
break
|
||||||
case 'mta':
|
case 'mta':
|
||||||
mtaBuild script: script
|
mtaBuild script: script
|
||||||
break
|
break
|
||||||
case 'npm':
|
case 'npm':
|
||||||
npmExecute script: script
|
npmExecuteScripts script: script, install: config.npmInstall, runScripts: config.npmRunScripts
|
||||||
break
|
break
|
||||||
case ['docker', 'kaniko']:
|
case ['docker', 'kaniko']:
|
||||||
DockerUtils dockerUtils = new DockerUtils(script)
|
DockerUtils dockerUtils = new DockerUtils(script)
|
||||||
|
Loading…
Reference in New Issue
Block a user