Set environment variable before executing maven (In a jenkins build)
Asked Answered
A

2

12

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.

Allout answered 3/10, 2013 at 13:5 Comment(0)
B
15

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

Beetroot answered 3/10, 2013 at 16:1 Comment(0)
R
0

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.

Rhinencephalon answered 3/10, 2013 at 14:52 Comment(1)
Yes, Jenkins supports several different ways to set environment variables.Beetroot

© 2022 - 2024 — McMap. All rights reserved.