Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add path variable to job shell

Tags:

jenkins

hudson

I am setting up Jenkins to replace our current TeamCity CI build.

I have created a free-style software project so that I can execute a shell script. The Shell script runs the mvn command.

But the build fails complaining that the 'mvn' command cannot be found.

I have figured that this is because Jenkins is running the build in a different shell, which does not have Maven on it's path.

My question is; how do I add the path so 'mvn' is found in my Shell script? I've looked around but can't spot where the right place might be.

Thanks for your time.

like image 460
C0deAttack Avatar asked Sep 08 '11 14:09

C0deAttack


People also ask

How is the PATH variable used by the shell?

The PATH environment variable is a colon-delimited list of directories that your shell searches through when you enter a command. Program files (executables) are kept in many different places on the Unix system. Your path tells the Unix shell where to look on the system when you request a particular program.

How do I set the PATH variable in Bash?

For Bash, you simply need to add the line from above, export PATH=$PATH:/place/with/the/file, to the appropriate file that will be read when your shell launches. There are a few different places where you could conceivably set the variable name: potentially in a file called ~/. bash_profile, ~/. bashrc, or ~/.


2 Answers

I solved this by exporting and setting the Path in the Jenkins Job configuration where you can enter shell commands. So I set the environments variable before I execute my Shell script, works a treat.

like image 112
C0deAttack Avatar answered Sep 25 '22 02:09

C0deAttack


Some possible solutions:

  • You can call maven with an absolute path
  • You configure a global environment variable in the jenkins system settings with the absolute path to your maven instance, and use this in your script call (if you use the inline shell script, I don't know if those are substituted to a called script, you have to test)
  • You use a maven project and configure your maven instance in the jenkins system settings

ps.: Usually /bin/sh is chosen from Jenkins, if you want to switch to eg. bash, you can configure this in the jenkins system settings, in case you want to configure global environment variables.

like image 43
Dag Avatar answered Sep 25 '22 02:09

Dag