mirror of
https://github.com/SAP/jenkins-library.git
synced 2024-12-14 11:03:09 +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:
parent
d66607c31a
commit
79894bb36f
@ -56,7 +56,11 @@ class DockerArtifactVersioning extends ArtifactVersioning {
|
|||||||
def version = null
|
def version = null
|
||||||
for (def i = 0; i < lines.size(); i++) {
|
for (def i = 0; i < lines.size(); i++) {
|
||||||
if (lines[i].startsWith('FROM') && lines[i].indexOf(':') > 0) {
|
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
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -51,6 +51,18 @@ class DockerArtifactVersioningTest extends BasePiperTest{
|
|||||||
assertTrue(loggingRule.log.contains('[DockerArtifactVersioning] Version from Docker base image tag: 1.2.3'))
|
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
|
@Test
|
||||||
void testVersioningEnv() {
|
void testVersioningEnv() {
|
||||||
av = new DockerArtifactVersioning(nullScript, [filePath: 'Dockerfile', dockerVersionSource: 'TEST'])
|
av = new DockerArtifactVersioning(nullScript, [filePath: 'Dockerfile', dockerVersionSource: 'TEST'])
|
||||||
|
@ -0,0 +1,5 @@
|
|||||||
|
FROM registry:4444/path/image:1.2.3
|
||||||
|
|
||||||
|
USER root
|
||||||
|
|
||||||
|
ENV TEST 2.3.4
|
@ -0,0 +1,5 @@
|
|||||||
|
FROM registry:4444/path/image
|
||||||
|
|
||||||
|
USER root
|
||||||
|
|
||||||
|
ENV TEST 2.3.4
|
Loading…
Reference in New Issue
Block a user