The gradlew clean build command failed with an error reading from client configuration
Asked by apulikkal:

I have a micronaut service up and running, recently I added the discovery client configurations for reading the values from bootstrap.yaml. When I apply gradlew clean test in my local test is executed properly it is a success. But when it runs from the bitbucket pipeline it fails.

Below are the dependencies added in build.gradle

implementation("io.micronaut.kubernetes:micronaut-kubernetes-discovery-client")  
implementation("io.micronaut.kubernetes:micronaut-kubernetes-client")  

Below are the errors from the pipeline  

09:51:06.448` `[Test worker]` `INFO i.m.context.env.DefaultEnvironment - Established active environments: [test, k8s, cloud, ec2]  
09:51:06.453` `[Test worker]` `INFO i.m.context.env.DefaultEnvironment - Established active environments: [test, k8s, cloud, ec2]  
09:51:06.635` `[Test worker]` `INFO i.m.context.DefaultBeanContext - Reading bootstrap environment configuration  
09:51:06.692` `[Test worker]` `DEBUG` `i.m.context.condition.Condition - Configuration: io.micronaut.discovery.spring.config will not be loaded due to failing conditions:  
09:51:06.692` `[Test worker]` `DEBUG` `i.m.context.condition.Condition - * Property [micronaut.config-client.enabled] with value [false] does not equal required value: true  
09:51:06.693` `[Test worker]` `DEBUG` `i.m.context.condition.Condition - Configuration: io.micronaut.discovery.vault.config will not be loaded due to failing conditions:  
09:51:06.695` `[Test worker]` `DEBUG` `i.m.context.condition.Condition - * Property [micronaut.config-client.enabled] with value [false] does not equal required value: true  
09:51:06.696` `[Test worker]` `DEBUG` `i.m.context.condition.Condition - Configuration: io.micronaut.http.server.cors will not be loaded due to failing conditions:  
09:51:06.696` `[Test worker]` `DEBUG` `i.m.context.condition.Condition - * Required property [micronaut.server.cors.enabled] with value [true] not present  
09:51:06.697` `[Test worker]` `DEBUG` `i.m.context.condition.Condition - Configuration: io.micronaut.discovery.consul.client.v1 will not be loaded due to failing conditions:  
09:51:06.697` `[Test worker]` `DEBUG` `i.m.context.condition.Condition - * Required property [consul.client] with value [null] not present  
09:51:06.698` `[Test worker]` `DEBUG` `i.m.context.condition.Condition - Configuration: io.micronaut.discovery.vault.config.v1 will not be loaded due to failing conditions:  
09:51:06.699` `[Test worker]` `DEBUG` `i.m.context.condition.Condition - * Required property [vault.client.kv-version] with value [V1] not present  
09:51:06.699` `[Test worker]` `DEBUG` `i.m.context.condition.Condition - Configuration: io.micronaut.discovery.vault.config.v2 will not be loaded due to failing conditions:  
09:51:06.699` `[Test worker]` `DEBUG` `i.m.context.condition.Condition - * Required property [vault.client.kv-version] with value [V2] not present  
09:51:06.703` `[Test worker]` `DEBUG` `i.m.context.condition.Condition - Bean [io.micronaut.discovery.client.config.$DistributedPropertySourceLocator$Definition] will not be loaded due to failing conditions:  
09:51:06.703` `[Test worker]` `DEBUG` `i.m.context.condition.Condition - * Property [micronaut.config-client.enabled] with value [false] does not equal required value: true  
09:51:06.736` `[Test worker]` `DEBUG` `i.m.context.condition.Condition - Configuration: io.micronaut.discovery.spring.config will not be loaded due to failing conditions:  
09:51:06.737` `[Test worker]` `DEBUG` `i.m.context.condition.Condition - * Property [micronaut.config-client.enabled] with value [false] does not equal required value: true  
09:51:06.738` `[Test worker]` `DEBUG` `i.m.context.condition.Condition - Configuration: io.micronaut.discovery.vault.config will not be loaded due to failing conditions:  
09:51:06.738` `[Test worker]` `DEBUG` `i.m.context.condition.Condition - * Property [micronaut.config-client.enabled] with value [false] does not equal required value: true  
09:51:06.739` `[Test worker]` `DEBUG` `i.m.context.condition.Condition - Configuration: io.micronaut.discovery.consul.client.v1 will not be loaded due to failing conditions:  
09:51:06.739` `[Test worker]` `DEBUG` `i.m.context.condition.Condition - * Required property [consul.client] with value [null] not present  
09:51:06.740` `[Test worker]` `DEBUG` `i.m.context.condition.Condition - Configuration: io.micronaut.discovery.vault.config.v1 will not be loaded due to failing conditions:  
09:51:06.740` `[Test worker]` `DEBUG` `i.m.context.condition.Condition - * Required property [vault.client.kv-version] with value [V1] not present  
09:51:06.740` `[Test worker]` `DEBUG` `i.m.context.condition.Condition - Configuration: io.micronaut.discovery.vault.config.v2 will not be loaded due to failing conditions:  
09:51:06.740` `[Test worker]` `DEBUG` `i.m.context.condition.Condition - * Required property [vault.client.kv-version] with value [V2] not present  
09:51:06.766` `[Test worker]` `DEBUG` `i.m.context.condition.Condition - Bean [io.micronaut.liquibase.$GormMigrationRunnerDefinition] will not be loaded due to failing conditions:  
09:51:06.766` `[Test worker]` `DEBUG` `i.m.context.condition.Condition - * Class [org.grails.orm.hibernate.HibernateDatastore] is not present  
09:51:06.767` `[Test worker]` `DEBUG` `i.m.context.condition.Condition - Bean [io.micronaut.liquibase.$$GormMigrationRunnerDefinition$InterceptedDefinition] will not be loaded due to failing conditions:  
09:51:06.768` `[Test worker]` `DEBUG` `i.m.context.condition.Condition - * Class [org.grails.orm.hibernate.HibernateDatastore] is not present  
09:51:06.772` `[Test worker]` `DEBUG` `i.m.context.condition.Condition - Bean [io.micronaut.rabbitmq.metrics.$RabbitMetricsInterceptor$Definition] will not be loaded due to failing conditions:  
09:51:06.773` `[Test worker]` `DEBUG` `i.m.context.condition.Condition - * Class [io.micrometer.core.instrument.MeterRegistry] is not present  
09:51:06.788` `[Test worker]` `DEBUG` `i.m.context.condition.Condition - Bean [Definition: io.micronaut.transaction.jdbc.TransactionAwareDataSource] will not be loaded due to failing conditions:  
09:51:06.790` `[Test worker]` `DEBUG` `i.m.context.condition.Condition - * Existing bean [io.micronaut.jdbc.spring.DataSourceTransactionManagerFactory] of type [class io.micronaut.jdbc.spring.DataSourceTransactionManagerFactory] registered in context  
09:51:06.795` `[Test worker]` `DEBUG` `i.m.context.condition.Condition - Bean [io.micronaut.web.router.version.$VersionAwareRouterListener$Definition] will not be loaded due to failing conditions:  
09:51:06.795` `[Test worker]` `DEBUG` `i.m.context.condition.Condition - * Required property [micronaut.router.versioning.enabled] with value [true] not present  
09:51:06.932` `[Test worker]` `DEBUG` `i.m.context.condition.Condition - Bean [io.micronaut.transaction.jdbc.$DelegatingDataSourceResolver$Definition] will not be loaded due to failing conditions:  
09:51:06.934` `[Test worker]` `DEBUG` `i.m.context.condition.Condition - * Class [org.springframework.jdbc.datasource.DataSourceTransactionManager] is not absent  
09:51:07.048` `[Test worker]` `DEBUG` `i.m.context.condition.Condition - Bean [io.micronaut.reactor.convert.$ReactorToRxJava3ConverterRegistrar$Definition] will not be loaded due to failing conditions:  
09:51:07.049` `[Test worker]` `DEBUG` `i.m.context.condition.Condition - * Class [io.reactivex.rxjava3.core.Maybe] is not present  
09:51:07.050` `[Test worker]` `DEBUG` `i.m.context.condition.Condition - Bean [io.micronaut.http.netty.channel.converters.$KQueueChannelOptionFactory$Definition] will not be loaded due to failing conditions:  
09:51:07.050` `[Test worker]` `DEBUG` `i.m.context.condition.Condition - * Class [io.netty.channel.kqueue.KQueue] is not present  
09:51:07.052` `[Test worker]` `DEBUG` `i.m.context.condition.Condition - Bean [io.micronaut.reactive.flow.converters.$FlowConverterRegistrar$Definition] will not be loaded due to failing conditions:  
09:51:07.052` `[Test worker]` `DEBUG` `i.m.context.condition.Condition - * Class [kotlinx.coroutines.reactive.ReactiveFlowKt] is not present  
09:51:07.067` `[Test worker]` `DEBUG` `i.m.context.condition.Condition - Bean [io.micronaut.http.netty.channel.converters.$EpollChannelOptionFactory$Definition] will not be loaded due to failing conditions:  
09:51:07.068` `[Test worker]` `DEBUG` `i.m.context.condition.Condition - * Class [io.netty.channel.epoll.Epoll] is not present  
09:51:07.069` `[Test worker]` `DEBUG` `i.m.context.condition.Condition - Bean [io.micronaut.http.netty.channel.converters.$EpollChannelOptionFactory$Definition] will not be loaded due to failing conditions:  
09:51:07.070` `[Test worker]` `DEBUG` `i.m.context.condition.Condition - * Class [io.netty.channel.epoll.Epoll] is not present  
09:51:07.071` `[Test worker]` `DEBUG` `i.m.context.condition.Condition - Bean [io.micronaut.http.netty.channel.converters.$KQueueChannelOptionFactory$Definition] will not be loaded due to failing conditions:  
09:51:07.071` `[Test worker]` `DEBUG` `i.m.context.condition.Condition - * Class [io.netty.channel.kqueue.KQueue] is not present  
09:51:07.071` `[Test worker]` `DEBUG` `i.m.context.condition.Condition - Bean [io.micronaut.http.netty.channel.converters.$KQueueChannelOptionFactory$Definition] will not be loaded due to failing conditions:  
09:51:07.072` `[Test worker]` `DEBUG` `i.m.context.condition.Condition - * Class [io.netty.channel.kqueue.KQueue] is not present  
09:51:07.359` `[Test worker]` `DEBUG` `i.m.context.condition.Condition - Bean [io.micronaut.logging.$PropertiesLoggingLevelsConfigurer$Definition] will not be loaded due to failing conditions:  
09:51:07.360` `[Test worker]` `DEBUG` `i.m.context.condition.Condition - * Required property [logger.levels] with value [null] not present  
09:51:07.371` `[Test worker]` `WARN i.m.k.c.DefaultNamespaceResolver - An error has occurred when reading the file: [/var/run/secrets/kubernetes.io/serviceaccount/namespace]. Kubernetes namespace will be set to: default  
09:51:08.110` `[OkHttp <http://localhost:8080/>...]` `ERROR` `i.m.k.client.OkHttpClientLogging - HTTP FAILED: Failed to connect to localhost/0:0:0:0:0:0:0:1:8080  
java.net.ConnectException: Failed to connect to localhost/0:0:0:0:0:0:0:1:8080


Answers:
author: Patrik S
body: Hello [@apulikkal](/t5/user/viewprofilepage/user-id/4928453) ,

Welcome to Atlassian Community!

From the error being shown in the logs it looks like your build is trying to connect to a service in <http://localhost:8080/> which seems to have not been correctly started in the previous commands.

Since you mentioned you were able to execute it successfully when running locally, in order to understand if the issue is with Pipelines environment itself or with your current build setup, I'd like to ask you to run the build locally in a docker container and check if the same error happens.

You can follow the below documentation to debug your build locally :

* <https://support.atlassian.com/bitbucket-cloud/docs/debug-pipelines-locally-with-docker/>

This will make your environment closer to what you have when executing the build in Bitbucket Pipelines. Please make sure to use the same docker image as your pipeline build when starting your local container. Once you run it locally you can share the logs with us, so we can investigate further.

In case you have any questions, please let me know!

Thank you, [@apulikkal](/t5/user/viewprofilepage/user-id/4928453) .

Kind regards,

Patrik S

comments: author: apulikkal
body: Thanks [@Patrik S](/t5/user/viewprofilepage/user-id/4603309) for the reply,

Yes, the log says it is not able to connect to a localhost service, am getting this message when I apply command like bash gradlew clean test, below is the step from bitbucket-pipeline.yml file

```
- step:
    name: "Test"
    script:
      - export TESTCONTAINERS_RYUK_DISABLED=true
      - cd product-api
      - bash ./gradlew clean test
```

When I try this gradlew clean test command from my local windows machine it is successfully running, and also I tried it from a linux machine there also it worked.

Interesting this when I comment below two lines from build.gradle file it successfully running in bitbucket pipeline.

```
implementation("io.micronaut.kubernetes:micronaut-kubernetes-discovery-client")
implementation("io.micronaut.kubernetes:micronaut-kubernetes-client")
?
```

Bitbucket pipeline was running successfully before adding these dependencies, I added this because I want to read some configurations from bootstrap.yml file


author: Yevhen
body: [@apulikkal](/t5/user/viewprofilepage/user-id/4928453) the client fails to connect to a K8s cluster and falls back to localhost:8080. I do not think you are allowed to use incluster auth in pipelines otherwise you'd get access to the actual cluster where your job pod is running.

You can configure which cluster to connect to: <https://micronaut-projects.github.io/micronaut-kubernetes/snapshot/guide/#_authentication> but this has to be your Kube cluster.


author: apulikkal
body: [@Yevhen](/t5/user/viewprofilepage/user-id/3965218) When running the test it is not supposed to use the K8 cluster, it should run in the test container.


author: Yevhen
body: [@apulikkal](/t5/user/viewprofilepage/user-id/4928453) correct, a test container that a test wants to create using K8s API. This isn't supported in pipelines for obvious reasons. I'm just explaining what happens and why it works locally for you.


author: apulikkal
body: [@Yevhen](/t5/user/viewprofilepage/user-id/3965218) Thanks for the reply, I agree that a test with K8 API may not work, but let's say my data source configurations are reading from a config-map, but when a test runs it is not required to read from config-map that means when a test runs it is not required to use K8 API.

Datasource I have tested with bootstrap-test.yml by removing the config-map configurations but it is not working.

Any other way to not use K8 API in test mode?


author: Yevhen
body: [@apulikkal](/t5/user/viewprofilepage/user-id/4928453) I am sorry, I am not familiar with the framework you use. If during a test phase it needs access to K8s API...it needs it for some reason. I can only recommend using an external k8s cluster of course if you have a public one.


Tags: bitbucket-cloud

cloud