1
0
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:
Jesse Awan 2021-12-22 16:51:06 +01:00 committed by GitHub
parent 4d787ded6d
commit 9a387561b2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 71 deletions

View File

@ -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))
}
}

View File

@ -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) {