mirror of
https://github.com/SAP/jenkins-library.git
synced 2025-01-04 04:07:16 +02:00
remove docker native buildtool check (#3336)
* remove docker native buildtool check
This commit is contained in:
parent
4d787ded6d
commit
9a387561b2
@ -286,68 +286,23 @@ class BuildExecuteTest extends BasePiperTest {
|
||||
|
||||
@Test
|
||||
void testDocker() {
|
||||
boolean buildToolCalled = false
|
||||
binding.setVariable('docker', new DockerMock('test'))
|
||||
def pushParams = [:]
|
||||
helper.registerAllowedMethod('containerPushToRegistry', [Map.class], { m ->
|
||||
pushParams = m
|
||||
helper.registerAllowedMethod('kanikoExecute', [Map.class], { m ->
|
||||
buildToolCalled = true
|
||||
return
|
||||
})
|
||||
stepRule.step.buildExecute(
|
||||
script: nullScript,
|
||||
buildTool: 'docker',
|
||||
dockerImageName: 'path/to/myImage',
|
||||
dockerImageTag: 'myTag',
|
||||
dockerRegistryUrl: 'https://my.registry:55555'
|
||||
)
|
||||
|
||||
assertThat(pushParams.dockerBuildImage.image.toString(), is('path/to/myImage:myTag'))
|
||||
assertThat(pushParams.dockerRegistryUrl.toString(), is('https://my.registry:55555'))
|
||||
assertThat(nullScript.commonPipelineEnvironment.getValue('containerImage').toString(), is('path/to/myImage:myTag'))
|
||||
}
|
||||
|
||||
@Test
|
||||
void testDockerWithEnv() {
|
||||
nullScript.commonPipelineEnvironment.setArtifactVersion('1.0.0')
|
||||
binding.setVariable('docker', new DockerMock('test'))
|
||||
def pushParams = [:]
|
||||
helper.registerAllowedMethod('containerPushToRegistry', [Map.class], { m ->
|
||||
pushParams = m
|
||||
return
|
||||
})
|
||||
stepRule.step.buildExecute(
|
||||
script: nullScript,
|
||||
buildTool: 'docker',
|
||||
dockerImageName: 'path/to/myImage',
|
||||
dockerRegistryUrl: 'https://my.registry:55555'
|
||||
)
|
||||
|
||||
assertThat(pushParams.dockerBuildImage.image.toString(), is('path/to/myImage:1.0.0'))
|
||||
assertThat(pushParams.dockerRegistryUrl.toString(), is('https://my.registry:55555'))
|
||||
assertThat(nullScript.commonPipelineEnvironment.getValue('containerImage').toString(), is('path/to/myImage:1.0.0'))
|
||||
}
|
||||
|
||||
@Test
|
||||
void testDockerNoPush() {
|
||||
binding.setVariable('docker', new DockerMock('test'))
|
||||
def pushParams = [:]
|
||||
helper.registerAllowedMethod('containerPushToRegistry', [Map.class], { m ->
|
||||
pushParams = m
|
||||
return
|
||||
})
|
||||
stepRule.step.buildExecute(
|
||||
script: nullScript,
|
||||
buildTool: 'docker',
|
||||
dockerImageName: 'path/to/myImage',
|
||||
dockerImageTag: 'myTag',
|
||||
dockerRegistryUrl: ''
|
||||
)
|
||||
|
||||
assertThat(pushParams.dockerBuildImage, nullValue())
|
||||
assertThat(pushParams.dockerRegistryUrl, nullValue())
|
||||
assertThat(buildToolCalled, is(true))
|
||||
}
|
||||
|
||||
@Test
|
||||
void testKaniko() {
|
||||
binding.setVariable('docker', new DockerMock('test'))
|
||||
def buildToolCalled = false
|
||||
helper.registerAllowedMethod('kanikoExecute', [Map.class], { m ->
|
||||
buildToolCalled = true
|
||||
@ -359,5 +314,4 @@ class BuildExecuteTest extends BasePiperTest {
|
||||
)
|
||||
assertThat(buildToolCalled, is(true))
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -86,26 +86,7 @@ void call(Map parameters = [:]) {
|
||||
npmExecuteScripts script: script, install: config.npmInstall, runScripts: config.npmRunScripts
|
||||
break
|
||||
case ['docker', 'kaniko']:
|
||||
DockerUtils dockerUtils = new DockerUtils(script)
|
||||
if (config.buildTool == 'docker' && !dockerUtils.withDockerDaemon()) {
|
||||
config.buildTool = 'kaniko'
|
||||
echo "[${STEP_NAME}] No Docker daemon available, thus switching to Kaniko build"
|
||||
}
|
||||
if (config.buildTool == 'kaniko'){
|
||||
kanikoExecute script: script
|
||||
}else{
|
||||
ConfigurationHelper.newInstance(this, config)
|
||||
.withMandatoryProperty('dockerImageName')
|
||||
.withMandatoryProperty('dockerImageTag')
|
||||
|
||||
def dockerImageNameAndTag = "${config.dockerImageName}:${config.dockerImageTag}"
|
||||
def dockerBuildImage = docker.build(dockerImageNameAndTag, "${config.containerBuildOptions ?: ''} .")
|
||||
//only push if registry is defined
|
||||
if (config.dockerRegistryUrl) {
|
||||
containerPushToRegistry script: script, dockerBuildImage: dockerBuildImage, dockerRegistryUrl: config.dockerRegistryUrl
|
||||
}
|
||||
script.commonPipelineEnvironment.setValue('containerImage', dockerImageNameAndTag)
|
||||
}
|
||||
kanikoExecute script: script
|
||||
break
|
||||
default:
|
||||
if (config.dockerImage && config.dockerCommand) {
|
||||
|
Loading…
Reference in New Issue
Block a user