Git Bash: "bash: env: command not found" but only after running the 'export' command first. Why? - environment-variables

I use git bash on a windows 10 machine through Windows Terminal. The command 'env' works perfectly every time I start up a session in git bash. However, if I try to do any 'export' command, running any 'env' command after that will raise the error 'bash: env: command not found'. If I close my session and start another one, 'env' works perfectly again. Why is this happening?
I've tried all permutations of the 'env' command, but nothing works. The 'export' command always works, which I know because I tested it to see if it does indeed modify my PATH.
Note: I'm not sure what relevant system info would be helpful to include here, so please tell me what you'd need to solve this issue, but I'd prefer to include as little as possible for privacy.

Related

Jenkins Job to run SOQL query

I'm trying to get a Jenkins job to run sfdx force:data:soql:query commands in order to migrate configuration data sets between our production org and our sandboxes after a refresh. Certain configurations do not persist on a refresh so we need a way to move that data.
Running the queries from the command line on the Jenkins server work as expected, however the job when it runs fails with the following error:
'C:\Program' is not recognized as an internal or external command, operable program or batch file.
Build step 'Execute shell' marked build as failure
The job does three things:
Authorizes to the DevHub, lists out the connected orgs, and then performs a SQOL query to just print some data - 16 lines to be exact. Here are the commands in the shell script of the job:
sfdx force:auth:jwt:grant -i ${CONNECTED_APP_CONSUMER_KEY} -u ${DEV_HUB} -f ${JENKINS_HOME}/certs/prod/server.key -r [...] -a DevHub
sfdx force:org:list
sfdx force:data:soql:query -u ${DEV_HUB} -q "SELECT Id, Name FROM [...tablename...]" -r human
I am completely stumped on why this is happening. Again, running the SOQL command directly on the server through PowerShell or Command Line works as expected. I would appreciate any help with this.
This one stumped me for a long time but we finally got it figured out.
If you are seeing this error, make sure to check your machine's environmental variables. I saw a TON of other answers pointing to this as the issue where the install of SFDX path name had spaces in it as in C:|P:rogram Files\SFDX\bin but only showed some weird command line FOR loop that made no sense what so ever.
What we did was to completely uninstall all of SFDX making sure none of it was left on the machine and reinstalled into a folder we made where there was no spaces in the path name.
Once we did that, our job worked like it was supposed to. I hope this helps others who run into this same issue.

PsExec is not recognized as an internal or external command

I have a job that needs to run a script on a remote computer. I'm doing so by using psexec via "Execute windows batch command":
C:\PsExec.exe \\computername -u username -p password -accepteula c:\xxx.exe
When I run the job I get the following error:
c:\PsExec.exe is not recognized as an internal or external command
** PsExec.exe is located under c:\
Any ideas?
First Define psexec.exe path in environment varaiable "PATH" or else place psexec.exe file in C:\Windows\System32\
And to Download Psexec.exe file
https://download.sysinternals.com/files/PSTools.zip
One possible explanation is the version of PsExec.exe: 32bits or 64bits.
If you have the 32 one on a 64bits machine, that command would not be recognized indeed. PsExec64.exe would.
I can see the age of this question and my answer may not be relevant to this topic since I was technically trying to solve a different problem, but maybe this will help other people who are stuck.
c:\PsExec.exe is not recognized as an internal or external command
I was trying to disable the Maintenance Configurator with PSExec (my problem is the never ending maintenance bug) and kept running into the same error as the OP BUT I got PSexec64 to run this command:
C:\PsExec64.exe -s schtasks /change /tn >"\Microsoft\Windows\TaskScheduler\Maintenance Configurator" /DISABLE
BY checking the "Run this program as an administrator" option under the Compatibility settings for "PsExec64.exe"
Don't know if this has solved my problem yet, but I think the OP would have been able to run his process if he had done this. Dear OP did you ever solve that?

Different software binary being executed on Jenkins for the same path

I have installed gems binary at two places on my jenkins server, each is different version:
[myserver]$ /opt/chef/embedded/bin/gem --version
2.4.1
[myserver]$ /opt/chefdk/embedded/bin/gem --version
2.4.4
I am running a job on this jenkins server with following command : /opt/chefdk/embedded/bin/gem inabox
and I get an error saying :
ERROR: While executing gem ... (Gem::CommandLineError)
Unknown command inabox
However when i run the same command from the command line , it identifies the inabox option.
To debug , when I ran this command /opt/chefdk/embedded/bin/gem help commands from the console and command line the options available are different and the console output doesnt include "inabox" option.
To make sure that I use the correct binary , I have also exported the binary path : PATH=$PATH:/opt/chefdk/embedded/bin in the job , but that also doesnt solve any thing.
I suspect that for some reason , /opt/chef/embedded/bin/gem binary is getting executed instead of /opt/chefdk/embedded/bin/gem , but I am not sure how and how do I solve it. Any pointers?
EDIT1
Here is output of echo $PATH
Here is the output of the command when I run through Jenkins console : /opt/chefdk/embedded/bin/gem help commands
Here is the output of the command when I run through command line :
1) Restart Jenkins every time you make changes to environment variables
2) if jenkins is executing the code on a slave, you need to define the PATH in your Jenkins settings.
We identified that a GEM_PATH variable being injected into the Jenkins job was causing the gem command to not work as intended. To resolve the issue, we added the “unset GEM_PATH” line to the beginning of the shell portion of the Build steps. This allowed the gem command to again recognize the “inabox” option and successfully upload gems to the Ruby Gems server.

How to find output of shell command run by fastlane action?

Sometimes it happens that a fastlane action throws an error like:
ERROR [2016-11-06 03:34:20.16]: Shell command exited with exit status 48 instead of 0.
I found troubleshooting difficult, as --verbose is not not verbose enough. By action I don't mean sh action, which is rather special case, but other fastlane actions e.g. create_keychain. The action create_keychain calls shell command security create-keychain and when it fails there is no clue what happened.
How do I find output of a shell command run by fastlane's action?
How do I find what shell command including all parameters is fastlane actually trying to run?
The output of the shell command is printed out by default when you use the sh action. Alternatively you can also run the shell command directly yourself using backticks (standard Ruby)
puts `ls`
The answer is that there is no such option at the moment, but it should be easy to add it.
I have created git issue #6878 for it.

fpm is not recognised if executing script with jenkins and ssh

I am trying to execute a script over ssh connexion with Jenkins. I am using the SSH plugin and it is well configured. I arrive to execute the first part of the script, but when I try to execute a fpm command it says:
fpm: command not found
If I connect to the instance and run the same script that I call via Jenkins it runs and there is no error (fpm is installed).
So, I have created a test like a script test.sh:
#!/bin/bash -x
fpm
but, with Jenkins, I get the same error: fpm: command not found, while if I execute it I get a normal "parameter needed":
Missing required -s flag. What package source did you want? {:level=>:warn}
Missing required -t flag. What package output did you want? {:level=>:warn}
No parameters given. You need to pass additional command arguments so that I know what you want to build packages from. For example, for '-s dir' you would pass a list of files and directories. For '-s gem' you would pass a one or more gems to package from. As a full example, this will make an rpm of the 'json' rubygem: `fpm -s gem -t rpm json` {:level=>:warn}
Fix the above problems, and you'll be rolling packages in no time! {:level=>:fatal}
What am I missing? Why it cannot find fpm if it is installed?
Make sure fpm is in /usr/bin..
It seems that the problem came because the fpm was installed in the /home/user2connect/bin/, and the command was not recognised. For fixing this I had to call it wit the whole path:
/home/user2connect/bin/fpm ...
I have chosen to reinstall the fpm using sudo, so now it works.

Resources