Simple Engineer Notes
154 subscribers
147 photos
2 videos
49 links
Engineering insights from a simple perspective - focusing on DevOps, IaC, OS, automation and solutions without the complexity.

https://www.goncharov.xyz
Download Telegram
🤡 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 LLMHUBAPIKEY_text environment variable
2. setLLMHUBAPIKEY.sh script -> Creates .mvn/maven.config
3. Maven reads .mvn/maven.config -> Sets property LLMHUBAPIKEY=gen-xxx
4. Surefire plugin -> Uses property in argLine
5. Test JVM  -> Receives -DLLMHUBAPIKEY=gen-xxx as system property
6. 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 variable
2. Test code  -> Reads LLMHUBAPIKEY_text environment variable

Well, 3 times easier & much more simplier. RTFM

#java #jenkins #fail
👍2