I'm having trouble getting a consistent PATH for my teamcity agent

Viewed 20

I'm using ansible to setup teamcity agents. Part of that process is to add a directory to the path in .bashrc and .zshrc. We currently default to zsh. Unfortunately the PATH for the teamcity agent seems inconsistent.

If I run agent.sh start manually the path is correct. I also have an ansible task that restarts the service as part of the setup. This gives inconsistent results. The teamcity agent has the correct path on some hosts, but is missing the directory in .zshrc on other hosts.

Ansible Task:

- name: Stop kill agent.sh script
  command: sh /opt/teamcity-agent/buildAgent/bin/agent.sh stop kill -f
  become: yes

- name: Start agent.sh script
  command: sh /opt/teamcity-agent/buildAgent/bin/agent.sh start

agent.sh

...
    if [ "$command_name" = "start" ]; then
      NOHUP=""
      nohup id >/dev/null 2>&1 && NOHUP=nohup

      $NOHUP "$java_exec" $TEAMCITY_LAUNCHER_OPTS_ACTUAL -cp $TEAMCITY_LAUNCHER_CLASSPATH jetbrains.buildServer.agent.Launcher $TEAMCITY_AGENT_OPTS_ACTUAL jetbrains.buildServer.agent.AgentMain -file $CONFIG_FILE > "$LOG_DIR/output.log" 2> "$LOG_DIR/error.log" &
      launcher_pid=$!
      echo $launcher_pid > $PID_FILE

      echo "Done [$launcher_pid], see log at `cd $LOG_DIR && pwd`/teamcity-agent.log"
...

I suspect one possibility is that agent.sh isn't an interactive shell, and that I should update the path in .zshenv. But this working on some of the agents is throwing me off.

How does a teamcity agent get environmental variables from the host machine? And how can I fix this problem so that I have a consistent environment?

0 Answers
Related