1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2024-12-12 10:55:20 +02:00

Fix docker versioning with registry port (#686)

Fix issue when retrieving version via tag in `FROM` section.
We also need to consider that the registry may contain a port.

* Update DockerArtifactVersioning.groovy
* add error message for missing image tag in FROM line
This commit is contained in:
Oliver Nocon 2019-06-19 13:00:56 +02:00 committed by GitHub
parent d66607c31a
commit 79894bb36f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 27 additions and 1 deletions

View File

@ -56,7 +56,11 @@ class DockerArtifactVersioning extends ArtifactVersioning {
def version = null
for (def i = 0; i < lines.size(); i++) {
if (lines[i].startsWith('FROM') && lines[i].indexOf(':') > 0) {
version = lines[i].split(':')[1]
def imageParts = lines[i].split(':')
version = imageParts[imageParts.size()-1]
if (version.contains('/')) {
script.error "[${getClass().getSimpleName()}] FROM statement does not contain an explicit image version: ${lines[i]} "
}
break
}
}

View File

@ -51,6 +51,18 @@ class DockerArtifactVersioningTest extends BasePiperTest{
assertTrue(loggingRule.log.contains('[DockerArtifactVersioning] Version from Docker base image tag: 1.2.3'))
}
@Test
void testVersioningFromWithRegistryPort() {
DockerArtifactVersioning av = new DockerArtifactVersioning(nullScript, [filePath: 'Dockerfile_registryPort', dockerVersionSource: 'FROM'])
assertEquals('1.2.3', av.getVersion())
}
@Test
void testVersioningFromWithMissingTag() {
thrown.expectMessage('FROM statement does not contain an explicit image version')
new DockerArtifactVersioning(nullScript, [filePath: 'Dockerfile_registryPortNoTag', dockerVersionSource: 'FROM']).getVersion()
}
@Test
void testVersioningEnv() {
av = new DockerArtifactVersioning(nullScript, [filePath: 'Dockerfile', dockerVersionSource: 'TEST'])

View File

@ -0,0 +1,5 @@
FROM registry:4444/path/image:1.2.3
USER root
ENV TEST 2.3.4

View File

@ -0,0 +1,5 @@
FROM registry:4444/path/image
USER root
ENV TEST 2.3.4