-
Notifications
You must be signed in to change notification settings - Fork 41.6k
Closed
Description
Hi.
I'm using Spring Boot 2.6.3 and I've the spring-boot-maven-plugin configured in the following way:
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring-boot.version}</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
<execution>
<id>build-image</id>
<goals>
<goal>build-image</goal>
</goals>
<configuration>
<image>
<name>${docker.image-name}</name>
</image>
<docker>
<publishRegistry>
<username>${docker.credentials.username}</username>
<password>${docker.credentials.password}</password>
</publishRegistry>
</docker>
</configuration>
</execution>
</executions>
</plugin>where the registry credentials are simply empty as
<docker.credentials.username />
<docker.credentials.password />I've tried to set the publish flag dynamically with Groovy in order to set it to false if one of the credentials is missing.
Everything works fine if both the credentials are missing. As soon as one is specified, the publishRegistry block complains even though the publish flag is false.
The Groovy part is
<plugin>
<groupId>org.codehaus.gmavenplus</groupId>
<artifactId>gmavenplus-plugin</artifactId>
<version>1.13.1</version>
<dependencies>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>3.0.9</version>
<type>pom</type>
</dependency>
</dependencies>
<executions>
<execution>
<id>check-if-image-must-be-published</id>
<phase>validate</phase>
<goals>
<goal>execute</goal>
</goals>
</execution>
</executions>
<configuration>
<scripts>
<script><![CDATA[
def dockerCredentialsUsernamePropertyName = 'docker.credentials.username'
def dockerCredentialsPasswordPropertyName = 'docker.credentials.password'
def dockerCredentialsUsername = checkPropertyValue(dockerCredentialsUsernamePropertyName)
def dockerCredentialsPassword = checkPropertyValue(dockerCredentialsPasswordPropertyName)
if(!dockerCredentialsUsername || !dockerCredentialsPassword) {
project.properties['spring-boot.build-image.publish'] = false
}
String checkPropertyValue(String name) {
def value = getPropertyValue(name)
if(!value) {
log.warn "The property '$name' is not set or it's blank, therefore no image will be pushed."
}
return value
}
String getPropertyValue(String name) {
// property was defined from command line e.g.: -DpropertyName=value
def value = session.userProperties[name]?.trim()
if (!value) {
value = project.properties[name]?.trim()
}
return value
}
]]></script>
</scripts>
</configuration>
</plugin>Ideally, if the publish flag is false, I would expect that the registry is completely ignored since it will not be used anyway.
Metadata
Metadata
Assignees
Labels
type: bugA general bugA general bug