🤡 2 Ways to solve the problem or RTFM
The task was quite simple:
1. build a java app via maven
2. during the build run some tests
3. the tests should connect to external service
4. the API key must be passed as an env var
The problem was at the first glance during a build wasn't possible to pass env vars to maven:
- the custom jenkins library was used
- the was no way to modified it
- the library was designed to follow the very specific flow
So, initial solution was:
1. Jenkins Pipeline -> Exposes credential as
2. setLLMHUBAPIKEY.sh script -> Creates
3. Maven reads
4. Surefire plugin -> Uses property in
5. Test JVM -> Receives
6. Test code -> Reads via
It worked, but was over engenieried and too complicated. Hopefully, after reading docs for the jenkins library it was spotted that there is ability to pass env vars to during maven build and solution was
1. Jenkins Pipeline -> Exposes credential as
2. Test code -> Reads
Well, 3 times easier & much more simplier. RTFM
#java #jenkins #fail
The task was quite simple:
1. build a java app via maven
2. during the build run some tests
3. the tests should connect to external service
4. the API key must be passed as an env var
The problem was at the first glance during a build wasn't possible to pass env vars to maven:
- the custom jenkins library was used
- the was no way to modified it
- the library was designed to follow the very specific flow
So, initial solution was:
1. Jenkins Pipeline -> Exposes credential as
LLMHUBAPIKEY_text environment variable2. setLLMHUBAPIKEY.sh script -> Creates
.mvn/maven.config3. Maven reads
.mvn/maven.config -> Sets property LLMHUBAPIKEY=gen-xxx4. Surefire plugin -> Uses property in
argLine5. Test JVM -> Receives
-DLLMHUBAPIKEY=gen-xxx as system property6. Test code -> Reads via
System.getProperty("LLMHUBAPIKEY")It worked, but was over engenieried and too complicated. Hopefully, after reading docs for the jenkins library it was spotted that there is ability to pass env vars to during maven build and solution was
1. Jenkins Pipeline -> Exposes credential as
LLMHUBAPIKEY_text environment variable2. Test code -> Reads
LLMHUBAPIKEY_text environment variableWell, 3 times easier & much more simplier. RTFM
#java #jenkins #fail
👍2