import os, sys print('Step info in a python shell.') print('Python executable: ' + sys.executable) print('Shell path: ' + os.environ['PATH'])**Step 2 commands** (using /bin/bash as a shell)
echo "Step info in a bash shell." echo "System path in Command(s) shell: $PATH" echo "Next, running a python script:" /tmp/show_paths.py**remote script contents**
#!/usr/bin/env python import os, sys print('Remote information.') print('Python executable: ' + sys.executable) print('Shell path: ' + os.environ['PATH'])**Output of step 1**
Step info in a python shell. Python executable: /istginfra/main/python/2.7.5/ubuntu/x86_64/bin/python Shell path: /usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/opt/electriccloud/electriccommander/bin:/home/build/scripts:/home/build/bin:/opt/electriccloud/electriccommander/bin**Output of step 2**
Step info in a bash shell. System path in \Command(s) shell: /usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/opt/electriccloud/electriccommander/bin:/home/build/scripts:/home/build/bin:/opt/electriccloud/electriccommander/bin Next, running a python script: Remote information. Python executable: /usr/bin/python Shell path: /usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/opt/electriccloud/electriccommander/bin:/home/build/scripts:/home/build/bin:/opt/electriccloud/electriccommander/bin**The logged in user environment:** (what I want to see!)
$ echo $PATH /istginfra/main/ruby/2.0.0/ubuntu/bin:/istginfra/main/python/2.7.5/ubuntu/x86_64/bin:/istginfra/main/python/2.7.5/ubuntu/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/opt/electriccloud/electriccommander/bin:/opt/electriccloud/electriccommander/bin:/home/build/scripts:/home/build/binThe interpreter cannot be hard-coded in first line of the scripts. The scripts may be run on cygwin or a redhat host. And, the location of the interpreter binary can change. So, how do I modify the environment and/or search path that Commander uses?
Answer by aviduser · Feb 10, 2014 at 03:32 PM
You could just modify the agent user's shell environment, for example .bash_profile, to make the path to the custom python directory at the front of the PATH env variable, but that might not satisfy all of your requirements.
For the past decade, we've used a strategy in our legacy (non-EC) build system which allows to have multiple tool versions on the same machine. We've ported this forward to EC, and a very simplified version of what we do is:
Then, in our Perl code we do something like this:
my $pyPath = "/myResource/asset:python_2.7/path"; `$pyPath myCode.py`;
I suppose the shell version could be the following, as long as there are no spaces in the 'path':
$[/myResource/asset:python_2.7/path] myCode.py
In summary, this mechanism allows us to install a tool anywhere on the machine, and as long as we reference it correctly, we'll always run the correct version of the tool.
Electric Cloud powers Continuous Delivery, helping organizations developing deliver better software faster by automating and accelerating build, test, and deployment processes at scale. Industry leaders like Qualcomm, SpaceX, Cisco, GE, Gap, and E*TRADE use Electric Cloud solutions to boost DevOps productivity and Agile throughput.