command not found from Jenkins Execute Shell
Asked Answered
T

3

7

Hi Jenkins and AWS Guru's

I already look online for any possible solutions but not getting a solution for my problem. I just issued an "eb --version" on Jenkins execute shell under a test project but getting "eb: command not found" during the execution.

Wierd thing is if I issue the same command on the Jenkins box via CLI I'm getting a good response from it. Any suggestions for the fix please? thanks in advance

Tweeze answered 13/9, 2017 at 13:38 Comment(0)
B
13

Your Jenkins setup has a different path than the user you logged in with.

There are two solutions:

  1. Add the path to the executable in the PATH environment variable. Use where eb to find the correct path. Then in Jenkins, click on Manage Jenkins -> Configure System, Global Properties. Check Environment Variables. Set Name to PATH. Set Value to $PATH:/path/to/eb. Then restart Jenkins.

  2. Call the eb command with its fully qualified path.

EDIT: Added steps to update path in Jenkins.

Bravo answered 13/9, 2017 at 14:34 Comment(18)
Thanks for the inputs Rodrigo, however my Jenkins runs under a linux environment. I'm not really sure what was changed but before when I issue "eb --version" from Jenkins execute shell it responds back correctly. I would like to have the "eb --version" command executable on Jenkins execute shell (without absolute path format) same way that I execute it on the linux boxTweeze
Yes I understand. Try #2 the above. Type 'where eb' in your login shell, then pass the full path to the command to confirm. Then if that works, you can be certain it is a path issue. Then you can fix the Path in jenkins. I'll try to find a Linux specifc path change for Jenkins.Bravo
Another test to confirm: create a job that runs a shell command echo $PATH. Compare that output with the result from where eb. There should be a discrepency.Bravo
Hi Rodrigo, it is already working when issuing the "eb --version" on the linux shell, the issue that I encounter is it doesn't work the same when issuing the same command in Jenkins UI (Pre Build Step Execute Shell)Tweeze
Yes I understand the issue. My solution will resolve the problem so that you can run the eb command in the Jenkins shell as you do in the login shell. Kindly follow the suggestions and let me know.Bravo
Result from echo $PATH _=/bin/env + echo 'Echoing Path' Echoing Path + echo /usr/lib/jvm/java-1.8.0-openjdk/bin:/sbin:/usr/sbin:/bin:/usr/bin /usr/lib/jvm/java-1.8.0-openjdk/bin:/sbin:/usr/sbin:/bin:/usr/bin + echo 'Issuing EB command without absolute path' Issuing EB command without absolute path + eb --version /tmp/jenkins8207102572563280583.sh: line 17: eb: command not found Build step 'Execute shell' marked build as failure Finished: FAILURETweeze
What does where eb return when you execute that from the login shell?Bravo
I forgot to refresh the page, the eb path when "which eb" is issued on linux is "/usr/local/bin/eb" I have tried the following and restarted jenkins but still getting the same issue Name: PATH VALUE: $PATH:/usr/local/bin/ebTweeze
ok yes there is your issue. The path to eb in not in your Jenkins path. But the path you provided is not correct. The correct path is /usr/local/bin/. Do not include eb in your path. The correct value is $PATH:/usr/local/bin Can you make that change and try again?Bravo
still not getting okay I used NAME=$PATH and VALUE: $PATH:/usr/local/binTweeze
Name is PATH not $PATHBravo
sorry Rodrigo typo written there, yes I used the NAME=PATH and VALUE=$PATH:/usr/local/bin/ I'm still not getting lucky yetTweeze
Well it should work. But for now suggest you use the direct path. Plan C is to login as the jenkins user, and update their profile with the correct path.Bravo
Are you restarting?Bravo
Its working here for sure. Now when I do the Echo Paht job, I see it in the path: Building in workspace /var/jenkins_home/workspace/Echo Path [Echo Path] $ /bin/sh -xe /tmp/jenkins5269326130697457694.sh + echo /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/bin:/usr/local/bin Likewise when I run a comand from that path, it resolves correctly. Can you try and confirm the path via echo? The steps I provided work fore sure. Double check your output.Bravo
Yup, I reatrted Jenkins as you suggested [EnvInject] - Loading node environment variables. Building on master in workspace /var/lib/jenkins/workspace/test/projects/eb-test [eb-test] $ /bin/bash -x /tmp/jenkins1234567890123.sh + echo /usr/lib/jvm/java-1.8.0-openjdk/bin:/usr/lib/jvm/java-1.8.0-openjdk/bin/usr/lib/jvm/java-1.8.0-openjdk/bin:/usr/lib/jvm/java-1.8.0-openjdk/bin Finished: SUCCESSTweeze
Odd its not in the path. It certainly should be as managing the environment is a Jenkins setting. Something is not correct. It is a basic path issue for sure.Bravo
yup I was thinking it is also a simple path adjustment, I'll check and see more why does my jenkins behaves this way, thanks btw for taking an effort to help me here RodrigoTweeze
T
1

this is now fixed, need to create a properties file that was basically a copy of /var/lib/jenkins/.bash_profile file which would have the correct paths and add that in Jenkins settings. Allowing it to get the required paths. After properties file is created you need to set it on Jenkins-Configure section, Place a check on Prepare jobs environment then set the full path of the properties file (/var/lib/jenkins/environment_variables.properties) on the Properties File Path and restart Jenkins

Tweeze answered 14/9, 2017 at 6:24 Comment(1)
Where in the Jenkins settings is the file added?Sidedress
R
0

I had same issue and this worked for my AWS Linux, and no need to restart my Jenkins :)

Echo to know the eb path in your command line interface (where it does works):

echo ~/.local/bin

I got /home/ec2-user/.local/bin

Copy the above complete path in your Jenkins Shell, before your eb command:

export PATH=/home/ec2-user/.local/bin:$PATH

source ~/.bash_profile

Source: https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/eb-cli3-install-linux.html

Ridenour answered 3/9 at 1:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.