mirror of
https://github.com/SAP/jenkins-library.git
synced 2024-11-28 08:49:44 +02:00
cnbBuild triggered by buildExecute (#4498)
* Add cnbBuild to buildExecute * Error message change * Make if check simpler Co-authored-by: Alexander Link <33052602+alxsap@users.noreply.github.com> * Switch order of check --------- Co-authored-by: Linda Siebert <linda.siebert@sap.com> Co-authored-by: Linda Siebert <39100394+LindaSieb@users.noreply.github.com> Co-authored-by: Alexander Link <33052602+alxsap@users.noreply.github.com>
This commit is contained in:
parent
9ba76d7479
commit
9d27e0e7b2
@ -300,6 +300,51 @@ class BuildExecuteTest extends BasePiperTest {
|
||||
assertThat(buildToolCalled, is(true))
|
||||
}
|
||||
|
||||
@Test
|
||||
void testDockerWithoutCNB() {
|
||||
boolean kanikoExecuteCalled = false
|
||||
boolean cnbBuildCalled = false
|
||||
binding.setVariable('docker', new DockerMock('test'))
|
||||
def pushParams = [:]
|
||||
helper.registerAllowedMethod('kanikoExecute', [Map.class], { m ->
|
||||
kanikoExecuteCalled = true
|
||||
return
|
||||
})
|
||||
helper.registerAllowedMethod('cnbBuild', [Map.class], { m ->
|
||||
cnbBuildCalled = true
|
||||
return
|
||||
})
|
||||
stepRule.step.buildExecute(
|
||||
script: nullScript,
|
||||
buildTool: 'docker',
|
||||
)
|
||||
assertThat(cnbBuildCalled, is(false))
|
||||
assertThat(kanikoExecuteCalled, is(true))
|
||||
}
|
||||
|
||||
@Test
|
||||
void testDockerWithCNB() {
|
||||
boolean kanikoExecuteCalled = false
|
||||
boolean cnbBuildCalled = false
|
||||
binding.setVariable('docker', new DockerMock('test'))
|
||||
def pushParams = [:]
|
||||
helper.registerAllowedMethod('kanikoExecute', [Map.class], { m ->
|
||||
kanikoExecuteCalled = true
|
||||
return
|
||||
})
|
||||
helper.registerAllowedMethod('cnbBuild', [Map.class], { m ->
|
||||
cnbBuildCalled = true
|
||||
return
|
||||
})
|
||||
stepRule.step.buildExecute(
|
||||
script: nullScript,
|
||||
buildTool: 'docker',
|
||||
cnbBuild: true
|
||||
)
|
||||
assertThat(cnbBuildCalled, is(true))
|
||||
assertThat(kanikoExecuteCalled, is(false))
|
||||
}
|
||||
|
||||
@Test
|
||||
void testKaniko() {
|
||||
binding.setVariable('docker', new DockerMock('test'))
|
||||
@ -315,6 +360,49 @@ class BuildExecuteTest extends BasePiperTest {
|
||||
assertThat(buildToolCalled, is(true))
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCnbBuildCalledWhenConfigured() {
|
||||
def cnbBuildCalled = false
|
||||
def npmExecuteScriptsCalled = false
|
||||
helper.registerAllowedMethod('npmExecuteScripts', [Map.class], { m ->
|
||||
npmExecuteScriptsCalled = true
|
||||
})
|
||||
helper.registerAllowedMethod('cnbBuild', [Map.class], { m ->
|
||||
cnbBuildCalled = true
|
||||
return
|
||||
})
|
||||
assertThat(nullScript.commonPipelineEnvironment.getContainerProperty('buildpacks'), nullValue())
|
||||
|
||||
stepRule.step.buildExecute(
|
||||
script: nullScript,
|
||||
buildTool: 'npm',
|
||||
cnbBuild: true
|
||||
)
|
||||
|
||||
assertThat(npmExecuteScriptsCalled, is(true))
|
||||
assertThat(cnbBuildCalled, is(true))
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCnbBuildNotCalledWhenNotConfigured() {
|
||||
def cnbBuildCalled = false
|
||||
def npmExecuteScriptsCalled = false
|
||||
helper.registerAllowedMethod('npmExecuteScripts', [Map.class], { m ->
|
||||
npmExecuteScriptsCalled = true
|
||||
})
|
||||
helper.registerAllowedMethod('cnbBuild', [Map.class], { m ->
|
||||
cnbBuildCalled = true
|
||||
return
|
||||
})
|
||||
stepRule.step.buildExecute(
|
||||
script: nullScript,
|
||||
buildTool: 'npm',
|
||||
cnbBuild: false
|
||||
)
|
||||
assertThat(npmExecuteScriptsCalled, is(true))
|
||||
assertThat(cnbBuildCalled, is(false))
|
||||
}
|
||||
|
||||
@Test
|
||||
void testHelmExecuteCalledWhenConfigured() {
|
||||
def helmExecuteCalled = false
|
||||
|
@ -1,3 +1,5 @@
|
||||
import hudson.AbortException
|
||||
|
||||
import com.sap.piper.DockerUtils
|
||||
import com.sap.piper.GenerateDocumentation
|
||||
import com.sap.piper.Utils
|
||||
@ -33,6 +35,8 @@ import static com.sap.piper.Prerequisites.checkScript
|
||||
'npmInstall',
|
||||
/** For buildTool npm: List of npm run scripts to execute */
|
||||
'npmRunScripts',
|
||||
/** Defines if a container image(s) should be created with Cloud Native Buildpacks using the artifact produced by the `buildTool`. */
|
||||
'cnbBuild',
|
||||
/** toggles if a helmExecute is triggered at end of the step after invoking the build tool */
|
||||
'helmExecute'
|
||||
])
|
||||
@ -87,8 +91,7 @@ void call(Map parameters = [:]) {
|
||||
case 'npm':
|
||||
npmExecuteScripts script: script, install: config.npmInstall, runScripts: config.npmRunScripts
|
||||
break
|
||||
case ['docker', 'kaniko']:
|
||||
kanikoExecute script: script
|
||||
case ['docker', 'kaniko']: //handled below
|
||||
break
|
||||
default:
|
||||
if (config.dockerImage && config.dockerCommand) {
|
||||
@ -102,7 +105,15 @@ void call(Map parameters = [:]) {
|
||||
error "[${STEP_NAME}] buildTool not set and no dockerImage & dockerCommand provided."
|
||||
}
|
||||
}
|
||||
|
||||
if (config.cnbBuild) {
|
||||
if (config.buildTool in ['npm', 'gradle', 'maven', 'mta', 'docker']) {
|
||||
cnbBuild script: script
|
||||
} else {
|
||||
throw new AbortException("ERROR - 'cnbBuild' does not support '${config.buildTool}' as a buildTool.")
|
||||
}
|
||||
} else if (config.buildTool == 'kaniko' || config.buildTool == 'docker') {
|
||||
kanikoExecute script: script
|
||||
}
|
||||
if(config.helmExecute) {
|
||||
helmExecute script: script
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user