Jenkins job unable to access an environment variable - maven

I have a project that is setup as a job to build in Jenkins.
This project has multiple Maven modules.
One of the Maven module has a Maven task, which runs a Java program.
This Java program requires an environment variable which is available in the system.
When I run the Maven build cycle for that module locally in the terminal of the same system, the Java program is able to read the environment variable.
However in the Jenkins build, the Maven task fails as it is not being able to access that environment variable.
Is there anything else that I need to make this env variable visible to Jenkins Maven. I have tried restarting Jenkins after setting the env var, but to no avail.

Related

Setting dynamic password from Maven

We've started using an AWS CodeArtifact Maven repository. Before connecting, developers must run a command ("aws") to acquire a temporary access token. How can I configure Maven to acquire and use this token automatically, without requiring running a script, configuring an IDE or changing the simple command line "mvn install"?
Maybe there's a trick I'm overlooking.
The token must be "interpolated" in the element <server>/<password> in settings.xml. This file will pre-process either an environment variable ({$env.token}) or a Java system property ({$token}). It will not process a project property.
The repository password cannot be specified within the POM file.
The settings.xml file cannot use project properties.
The exec-maven-plugin cannot set an environment variable in the parent process (Windows). It can write to a file.
The properties-maven-plugin cannot set a dynamic system property (e.g., from a file or script output).
The surefire plugin binds to the test phase and forks a JVM.
The Windows setx command does not affect the running process.
UPDATE: Maven downloads repository metadata before the first phase, so no plugin will solve the problem.

After configuring Maven in Global tools of Jenkins, build step fails with error mvn not found

In Jenkins, I have configured Maven under Configure Global tools.
Next, created a FreeStyle job and in the build step with execute shell. When I write mvn -v, the build fails with error mvn not found. But when I do the same exercise with JAVA_HOME, java -version , prints the correct version.
To resolve the issue, I added a env variable under ( Manage Jenkins -> Configure System -> ENV Variable). Added a new variable M2_HOME with value ( maven home on Jenkins machine) and in the execute shell build step added a line PATH=$PATH:$M2_HOME/bin.
I am not sure if this is the best practice.

Location of Maven Home on Cloud Foundry

I have an application that programmatically runs Maven command "clean package" at runtime, using plugin maven-invoker.
To be able to run this application on Cloud Foundry, we need to set Maven Home on the invoker.
This question is similar to Maven Invoker: IllegalStateException, except that we are deploying on Cloud Foundry but don't know how to get the value for Maven Home.
Is it possible to get it from CF environment?
The Java build pack does not install Maven or set any Maven related environment variables. You can however set whatever environment variables that you like via cf set-env or in the env block of your manifest.yml file.
https://docs.cloudfoundry.org/devguide/deploy-apps/manifest.html#env-block
Your app when running on CF will run as the vcap user and it runs out of /home/vcap/app (or reference $HOME env variable). If you need to pick a location to use for Maven home, I would suggest putting it under that directory.

Can't Use Maven Environment Variables in Jenkins CI

So I'm trying use a Python script to get some information out of Jenkins after it's done with a Maven build, but the Maven environment variables that are supposed to be set (see here) are not. Anyone know whats up? I'm using the latest version of Jenkins.
I just realized that the version that supports environment variables isn't out yet.

Setting environment variables in Gradle

I am using the tomcat plugin to start Tomcat server using a war file i have built using the war plugin.
Before the app starts i need to set some environment variables.
Is there a way to do that?
From what I can see in the Gradle Tomcat plugin docs, the plugin runs Tomcat in the Gradle process. Environment variables for that process can only be set from outside Gradle, in a manner appropriate for your environment/OS. Alternatively, you might want to look into the Gradle Cargo and Gradle Arquillian plugins, which can also run containers in an external process.
PS: Please don't double-post here and on http://forums.gradle.org.

Resources