문제

I am setting up a jenkins slave on a machine that is supposed to build a maven project containing some native C code. The machine itself however, is proving to be a problem. The machine is hosting a fairly old program, that uses a lot of environment variables, like JAVA_HOME, that maven needs to function properly. In order to run maven on the slave machine, i need to set these environment variables, before executing maven, or maven, and other dependencies, such as ssh, will not run. I cant just change the variables permanently, so i need a way to change en environment variable before executing the maven build.

I can execute the build manually by setting the environment variables before executing mvn, and the build works like a charm. But i need jenkins to trigger the build automatically.

As i see it i need to either: Configure jenkins to set environment variables before executing maven or Configure maven use specific values instead of certain environment variables (In such a way that jenkins can handle the execution)

Your help is much appreciated.

도움이 되었습니까?

해결책

There are lots of options.

  • Configure the node to set the environment variable (under Node properties, check "environment variables")
  • for tools Jenkins set the necessary environments itself. In the node configuration you can set different paths for tools that are configured in the main configuration (under Node properties, check "Tool Locations"), I believe you don't need a plugin to have this option.
  • Use the EnvInject plugin (the Setenv Plugin is deprecated)
  • Use the Envfile Plugin
  • set the environments variables before the manual launch of Maven. You need to have both in the same build step. (worst solution)
  • create a java/maven configuration that is only valid on that particular node and use it in your job. This is only work if your job only runs on your special node and nowhere else.

I suggest the first or second Option

다른 팁

I imagine Jenkins might support setting of environment variables through the UI for job configuration. If not, you can certainly write a script that set's your environment and have jenkins execute that script when running your build job.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top