Inject environment variables into maven settings.xml not working

Hey all

I have tried getting my app to be built with maven, but need to inject user credentials for a private repository server into the settings.xml file, Currently I am using this kind of setup:

   <server>
        <id>server-id</id>
        <username>${env.USERNAME}</username>
        <password>${env.PASSWORD}</password>
    </server>

I have placed the settings.xml file in the root directory and can see in the logs that it has been detected and is being used, but the environment variables that I have setup are not being made available for maven to use.

Any advice would be appreciated.

Hi @Chase_Haasbroek, if you’ve added the USERNAME environment variable, you should reference it as ${USERNAME} instead of ${env.USERNAME}.

btw. it’s a good practice to keep credentials as secrets so ideally you should:

  1. create secret Secrets | Koyeb
  2. create env var which references this secret Environment Variables | Koyeb
1 Like

Hi @Pawel_Beza, thanks for the suggestions in keeping my secret data safe. I have made the needed changes per your suggestions :+1:

It seems that environment variables are not injected during the build phase if you are building from a git repository and using the Maven buildpack, but if you build from a Dockerfile and specify an ARG line inside this file then it seems to be fine.

Do you know of any way to get the environment variables injected during the build time when building from a github repo and using a buildpack?

Hi @Chase_Haasbroek, I’m not very experienced with buildpacks, but if you want to set environment variables during the build phase, you’ll need to define io.buildpacks.build.env in your project.toml. However, I’m not sure if they support environment variable interpolation, so you might have to hard-code the values, which isn’t ideal for sensitive credentials.

In that case, I’d recommend falling back to the Dockerfile approach.

Cheers!

1 Like