Search code examples
iosbashjenkinscocoapodszsh

unable to use zsh/bash in Jenkins Execute Shell


I am trying to run iOS builds in a remote Mac mini connected as an agent to Jenkins master running on Linux server. I have all the dependencies installed and env variables set up via .zshrc(zsh is the default shell in catalina and above).

When I run scripts(npm install, pod install and so on) through Execute Shell option in Jenkins Freestyle project, it throws npm command not found/ pod command not found. Even when I shebang with /bin/zsh at the start of script, it doesn't work.

Is there a way to switch shell to zsh/bash or import all configurations into sh in the jenkins build process?


Solution

  • Jenkins leverage the 'rc' file when it connects to the slave (via ssh) and load the env variable (This also means when you will change anything in the rc file you need to disconnect and reconnect the slave to load the changes). Now it depends on the default SHELL set for the User you used to connect the slave. You need to check that and align the env variable accordingly in the right rc file.

    In the current situation, if you don't want to change anything you could also do a

    source ~/.zshrc
    

    at the start of your script. This will load the env vars defined in that file

    One more way is to set the env variable for a node is under "Node Properties" in node configuration.