Zend certified PHP/Magento developer

Having problems with macOS [Monterey] environment variables and Jenkins

I have an issue “reading/recognizing” all of the environment variables with a Jenkins build.

All of those necessary variables have been set via Terminal and are properly written in both .bashrc and .zshrc .

My build.sh requires those environment variables to be set and when I am building manually (running build.sh via Terminal) – everything goes very smooth.

The issue I am having is when I try to build with Jenkins, it does not “read/recognize” those already set environment variables. When I start a build with the following Jenkinsfile I am not getting anything that is expected (as I would get in Terminal).

Jenkinsfile:

pipeline {
    agent {
        label 'MacAgent-AppleSilicon_Test'
    }

    options {
        timestamps()
        timeout(time: 4, unit: 'HOURS')
        disableConcurrentBuilds()
        }

    stages {
        stage ('Jenkins') {
            steps {
                sh '''
                    $SHELL
                    whoami
                    brew list
                    echo $HOME
                    echo $PATH
                    echo $NVM_DIR
                    echo $JAVA_HOME
                    echo $ANDROID_HOME
                    echo $ANDROID_SDK_ROOT
                    echo $ANDROID_NDK_HOME
                    nvm ls
                '''
            }
        }
    }
}

ONLY results I am getting are the following:

$SHELL => /bin/zsh
whoami => ec2-user
$PATH => /usr/bin:/bin:/usr/sbin:/sbin

Everything else return empty echo and for nvm ls – it fails since nvm: command not found.

Here is my .plist:

<key>Label</key> 
    <string>com.jenkins.ci</string> 
<key>UserName</key> 
    <string>ec2-user</string> 
<key>SessionCreate</key> 
<key>ProgramArguments</key> 
<array> 
    <string>java</string> 
    <string>-Djava.awt.headless=true</string> 
    <string>-jar</string> 
    <string>/Users/ec2-user/Jenkins/remoting.jar</string> 
    <string>-jnlpUrl</string> 
    <string>http://ip-of-jenkins-master/computer/mac_vm/slave-agent.jnlp</string> 
</array>
<key>KeepAlive</key>
<key>StandardOutPath</key> 
<string>/Users/ec2-user/Jenkins/stdout.log</string> 
<key>StandardErrorPath</key> 
<string>/Users/ec2-user/Jenkins/error.log</string> 

I have found a solution that works for now, I have set those Environment Variables on Jenkins – Nodes -> Slave_Agent -> Configure -> Node properties/Environment Variables.

This works for now but as soon as I start at least one build .bashrc and .zshrc are removed/gone from the macOS Agent.

Would really appreciate suggestions about possible solutions as to how to make Jenkins builds to read Environment Variables, without having it set under Node Properties.